简体   繁体   中英

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?

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_NODE s of the Radii1 XML_ELEMENT_NODE .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM