只读取xml中的rootnode的节点 [英] only read Nodes of a rootnode in xml
本文介绍了只读取xml中的rootnode的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个像这样的xml表:
hi guys,
i have a xml table like this:
<rootnode>
<parent1>
<child> text1 </child>
</parent1>
<parent2>
<child> text2 </child>
</parent2>
<parent3>
<child> text3</child>
</parent3>
</rootnode>
我只想在数据集或数组列表中存储点头列表.仅读取-parent1,parent2,parent3.不像这样parent1,child,text,parent2,child,text等.
请帮助我..
i want to store only noed list in a dataset or an arraylist. which only read - parent1, parent2, parent3. not like this. parent1,child,text,parent2,child,text etc..
please help me this..
推荐答案
只需访问
objXmlDoc.DocumentElement
作为XmlElement对象的根元素.
that is the root element as an XmlElement object.
System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
xdoc.LoadXml("<rootnode><parent1><child> text1 </child></parent1><parent2><child> text2 </child></parent2><parent3><child> text3</child></parent3></rootnode>");
foreach (System.Xml.XmlNode xnode in xdoc.DocumentElement.ChildNodes) {
// use xnode.Name
}
您是否尝试过获取节点然后转换为列表?
have you tried to get the nodes and then convert to list?
这篇关于只读取xml中的rootnode的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文