简体   繁体   中英

XMLNODE: how can i select this node with attribute in my xml

I have an xml with the following structure

<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

    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?

您需要第一个<name>元素的fname属性,因此应编写:

student.fname = row.SelectSingleNode("name/@fname");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM