XML Xpath Query
I have been converting some VB.Net XMl code to read specific XML by Elements as opposed to attribute values, and I have the follo开发者_如何学Pythonwing line that has stumped me:
Dim fNode As XmlNodeList = x.SelectNodes(String.Format("tables
/table
/field[
@pkid='{0}'
]", fk))
My questions is regarding the end part, how do I write that to check an elements value as opposed to the specific attribute? The specific element that I want to check is <PK>
and I want to evaluate it against fk.
Thanks.
tables/table/field[PK='{0}']
There is nothing special about attributes in this context - you can test against the value of the PK
element just as easily by simply removing the @
.
Example input xml:
<tables>
<table>
<field>
<PK>42</PK>
<!-- Other fields -->
</field>
</table>
</tables>
精彩评论