Re: [xml] Problem reading inner text when parsing through xpatha



Ram,

<a>
  <b>
    <!--asda-->
       <c c1="a">  Innext text</c>
       <d c1="a">  Innext text</d>
</b>
<b>
    <!--asda-->
       <c c1="a">  Innext text</c>
       <d c1="a">  Innext text</d>
</b>
</a>

<snip>

I am using something like this to parse
              xmlXPathObjectPtr result = GetXpathNodes(xpath); //Assuming this gets me the xpathObjectPtr
<snip>

                                 for (int i=0; i<  nodeset->nodeNr; i++)
                                 {
                                                 xmlChar *keyword= xmlNodeListGetString(doc, 
nodeset->nodeTab[i]->xmlChildrenNode, 1);
<snip>

Is this correct?    Its appending all new lines and spaces but no characters.
Yes, it is doing exactly what it should, from XML perspective, but not enough to get to where you want to go. The XML definition of 'inner' text differs from yours. You're looking for all the text content of all children of <b> (including <b>?). The xmlNodeListGetString() call returns the text content of a given element _only_. The text is usually contained inside TEXT children of a given node, hence the inclusion of node->xmlChildrenNode as one of the arguments.

In order for you to achieve what you want, you need to go through each of the ELEMENT children of <b> and execute xmlNodeListGetString() on them (in addition to <b>, if you expect <b> to have text content).

HTH,
Good luck!
Piotr



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