Vivek
Vivek

Reputation: 89

Xml read using libxml2 library

I have a XML file as below

<root>
<Radii1 VT = "121212 121212"/>
</root>

I am trying to read the xml using libxml2 library.

cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"Radii1"))){

    }

cur = cur->next;
}

Now , my problem is if i am printing the cur->name, first it is giving me text then next time it will give me Radii1 and again next time will give text and then will exit the code.

I am not sure why that is happening is the format of the xml not correct?

Upvotes: 0

Views: 119

Answers (1)

Sam Varshavchik
Sam Varshavchik

Reputation: 118445

The XML format is correct, but a node is not just an XML entity. You're seeing nodes in the XML document that represent text portions of the document; namely the whitespace -- and specifically the newlines -- between the XML entities.

What you want to do is examine the value in cur->type, whether it's an XML_ELEMENT_NODE, an XML_TEXT_NODE; or any one of various other kinds of XML nodes, and decide what you want to do with them.

And if you are searching for a particular attribute, like "VT", it would be one of the child XML_ATTRIBUTE_NODEs of the Radii1 XML_ELEMENT_NODE.

Upvotes: 1

Related Questions