本文介绍了将xml存储到arraylist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想将xml节点值之一存储到数组列表中.我的xml文件如下所示:
hi guys,
I want to store one of the xml node value into array list. My xml file look like this:
<creategroup>
<group>
<id>sdas</id>
<name>as</name>
</group>
<group>
<id>ss</id>
<name>sd</name>
</group>
</creategroup>
我只想将名称存储到数组列表中.
请帮助我.
谢谢!
I want to store only a name into array list.
Please help me with this.
Thanks!
推荐答案
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("~/SomeFiles/XMLFile2.xml"));
XmlNodeList xmlnodli = xmldoc.SelectNodes("creategroup/group/name");
List<string> strli = new List<string>();
foreach (XmlNode xm in xmlnodli)
{
strli.Add(xm.InnerText);
}
</string></string>
在上面的代码中,您必须将xmlpath传递给加载方法
并且selectNodes()用于基于xpath检索特定节点.
xpath就是节点流
我希望它也对您有用.
所有Best
In the above code you''ve to pass xmlpath to load method
And selectNodes() is used for retrieve particular node based on xpath.
xpath is nothing but flow of nodes
I hope it works for you also.
All the Best
这篇关于将xml存储到arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!