开发者

XML Xpath Query

开发者 https://www.devze.com 2023-02-11 17:14 出处:网络
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:

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消