[英]XMLNODE: how can i select this node with attribute in my xml
I have an xml with the following structure 我有一个具有以下结构的xml
<student>
<name fname="oliver">
</name>
<name fname="de">
</name>
<name fname="johnson">
</name>
</student>
my code is like this: 我的代码是这样的:
//after loading into an xmldocument called xmlrecord //加载到名为xmlrecord的xml文档后
XmlNode row = xmlRecord.SelectSingleNode("/student");
student.fname = row.SelectSingleNode("name[fname]");
But its not returning anything. 但是它什么也没返回。 Pls what is the best way to select the fname='johnson' node? 请选择fname ='johnson'节点的最佳方法是什么?
您需要第一个<name>
元素的fname
属性,因此应编写:
student.fname = row.SelectSingleNode("name/@fname");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.