每个循环的 Xml 节点读取
我正在尝试循环遍历 Xml 文件并在消息中显示帐户的值。
XmlNodeList nodeList = testDoc.SelectNodes("/details/row/var");
foreach (XmlNode no in nodeList)
{
XmlNode node = testDoc.SelectSingleNode("/details/row/var[@name='account']");
test.actual = node.Attributes["value"].Value;
MessageBox.Show(test.account);
}
消息框当前重复显示第一条记录,如何才能转到下一条记录?
感谢您提前提供意见。
I am trying to loop through an Xml file and display the value for account in a message.
XmlNodeList nodeList = testDoc.SelectNodes("/details/row/var");
foreach (XmlNode no in nodeList)
{
XmlNode node = testDoc.SelectSingleNode("/details/row/var[@name='account']");
test.actual = node.Attributes["value"].Value;
MessageBox.Show(test.account);
}
The message box is currently displaying the first record repeatidly, how can I get to the next record?
Thanks for your input in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您重复使用
testDoc
中的相同元素分配node
。不清楚test.account
是什么(可能是test.actual
的拼写错误)?no
是将迭代nodeList
内容的变量 - 我想您打算使用它。OP编辑后编辑
现在您已经向我们展示了 nodeList 是什么,我怀疑您想做这样的事情:
You are repeatedly assigning
node
with the same element fromtestDoc
. It is not clear whattest.account
is (perhaps a mistype fortest.actual
)?no
is the variable which will iterate the contents ofnodeList
- I imagine you intended to use that.EDIT following edit of OP
Now you've shown us what nodeList is, I suspect you want to do something like this instead :
这是父节点值的示例,用于获取子节点的信息。这里我使用 ReportItems ParentNode 和仅打印图像子节点。
如果您有疑问,请告诉我..
Here is the sample for parent node value to get information of the child nodes.here i am using the ReportItems ParentNode and Print only image child nodes.
let me know if you have doubt..
试试这个,
Try this,
请尝试以下操作:
Try the following:
我不是 100% 确定,但您可能需要使用递归。如果没有,它应该看起来像这样:
I'm not 100% sure, but you may need to use recursion. If not, it should just look like this:
您不应该花时间逐个节点地读取 xml。尝试反序列化:
You shouldn't spend time with reading the xml node by node. Try Deserialization: