Re: [xml] This code unlinks too much.



"John J. Boyer" <john boyer abilitiessoft com> writes:

The document is xhtml with <head and <body inside the <HTML tag. The 
code is pasted below the line of dashes. The problem area starts with 
the line

oldPrebSib = furbrl->prev;

curBrlNode is defined and set outside this function Itcontains a 
braille translation, in this case of a MathML 
expression. This has already been placed in transNode. curbrlNode 
follows a <math tag, with its subtree. The math expression is supposed 
to be replaced by transNode and curBrlNode removed. When I trace through 
the code with gdb it appears to work properly. However, xmlDocDump does 
not produce anything except the <head subtree within the <HTML tag 
of the xhtml document. 
In other words, the body is completely missing. Suggestions? Thanks.

Can you give a complete example? I tried with code below and it seems to
work:

brail.c:
=====================

#include <stdio.h>

#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>

static xmlNode *curBrlNode, *afterCurBrl;
static int useAfterCurBrl;

static int
finishBrlNode ()
{
  /* int wcLength; */
  /* int utf8Length; */
  /* unsigned char *transText = (unsigned char *) ud->outbuf2; */
  xmlNode *transNode;
  xmlNode *linkedTransNode;
  xmlNode *oldPrevSib;
  xmlNode *oldBrlNode;
  /* wcLength = ud->outbuf1_len_so_far; */
  /* utf8Length = ud->outbuf2_len; */
  /* wc_string_to_utf8 (ud->outbuf1, &wcLength, transText, &utf8Length); */
  xmlChar transText[] = "the translation...";
  transNode = xmlNewText (transText);
  oldPrevSib = curBrlNode->prev;
  if (oldPrevSib != NULL)
    {
      xmlUnlinkNode (oldPrevSib);
      xmlFreeNode (oldPrevSib);
    }
  linkedTransNode = xmlAddPrevSibling (curBrlNode, transNode);
  afterCurBrl = curBrlNode->next;
  useAfterCurBrl = 1;
  oldBrlNode = curBrlNode;
  xmlUnlinkNode (oldBrlNode);
  xmlFreeNode (oldBrlNode);
  return 1;
}

int main()
{
    xmlDocPtr doc = xmlReadFile("brail.xml", NULL, XML_PARSE_NOBLANKS);
    xmlXPathContextPtr ctxt = xmlXPathNewContext(doc);
    curBrlNode = xmlXPathEval("//cur-brl", ctxt)->nodesetval->nodeTab[0];

    finishBrlNode();
    xmlDocDump(stdout, doc);
    return 0;
}
================

brail.xml:
======================
<html>
  <body>
    <beginning> filler </beginning>
    <math>
      <subtree> subtree of math </subtree>
    </math>
    <cur-brl>
      <subtree> subtree of cur-brl </subtree>
    </cur-brl>
    <trailing-stuff> end filler </trailing-stuff>
  </body>
</html>
=================

Output:
====================
<?xml version="1.0"?>
<html><body><beginning> filler </beginning>the translation...<trailing-stuff> end filler 
</trailing-stuff></body></html>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]