[英]Xml read using libxml2 library
I have a XML file as below 我有一个如下的XML文件
<root>
<Radii1 VT = "121212 121212"/>
</root>
I am trying to read the xml using libxml2 library. 我正在尝试使用libxml2库读取xml。
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. 现在,我的问题是,如果我要打印cur-> name,首先是给我文本,然后是下次给我Radii1,再次是给文本,然后退出代码。
I am not sure why that is happening is the format of the xml not correct? 我不确定为什么会这样,xml的格式不正确?
The XML format is correct, but a node is not just an XML entity. XML格式是正确的,但是节点不仅是XML实体。 You're seeing nodes in the XML document that represent text portions of the document;
您正在XML文档中看到代表文档文本部分的节点。 namely the whitespace -- and specifically the newlines -- between the XML entities.
即XML实体之间的空白-尤其是换行符。
What you want to do is examine the value in cur->type, whether it's an XML_ELEMENT_NODE
, an XML_TEXT_NODE
; 您要做的是检查cur-> type中的值,是否为
XML_ELEMENT_NODE
, XML_TEXT_NODE
; or any one of various other kinds of XML nodes, and decide what you want to do with them. 或其他各种XML节点中的任何一种,然后决定要使用它们做什么。
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
. 如果你正在寻找一个特定的属性,如“VT”,这将是孩子一个
XML_ATTRIBUTE_NODE
的第Radii1
XML_ELEMENT_NODE
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.