根据输入读取xml数据 [英] to read xml data based on input
本文介绍了根据输入读取xml数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个下拉列表,需要从1-4中选择任何一个.
如果我选择1,我想读取第一个id(即,父id ="1")内部节点并将其存储到某个变量.
如果我选择2,则应存储第二个ID(即,父ID ="2")详细信息.
因此应在为"id"指定的值上读取xml文件.
xml文件看起来像这样
I have a dropdown list where i need to select any one from 1-4.
if i select 1 i want to read the first id(i.e parent id="1") inner nodes and store it to some variable.
If i select 2 the second id(i.e parent id="2") details should get stored.
so the xml file should be read on the value given for "id".
the xml file looks something like this
<root>
<greatgrandparent>
<grandparent>
<parent id="1">
<child somevalue="3"></child>
</parent>
<parent id="2">
<child somevalue="4"></child>
<child somevalue="5"></child>
</parent>
</grandparent>
</greatgrandparent>
</root>
有人可以帮我吗?
预先感谢.
can anyone help me out???
Thanks in advance.
推荐答案
以下是示例代码:
Here is the sample code:
XmlNodeList nodes = XMLRead.SelectNodes(@"grandparent");
foreach (XmlNode node in nodes)
{
string event1 = node.InnerText;
listBoxOuter.Items.Add(event1);
foreach (XmlNode n in node)
{
string event2 = n.FirstChild.InnerText;
listBoxOuter.Items.Add(event2);
XmlNodeList nodes2 = node.ChildNodes;
for (int i = 0, ii = nodes2.Count; i < ii; i++)
{
XmlNode n = nodes2.Item(i);
string event2 = n.InnerText;
listBoxInner.Items.Add(event2);
}
}
}
这篇关于根据输入读取xml数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文