0

I have been converting some VB.Net XMl code to read specific XML by Elements as opposed to attribute values, and I have the following 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.

1
  • EDIT: The element that I want to check against fk is called PK Commented Feb 18, 2011 at 15:00

1 Answer 1

1
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>
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, There are no elements in the newly defined XML that I am using. The pkid value is now determined within a fully formed pk element. It is that value that I would like to compare against fk. Thanks.
Have it working now taking away the @sign like you said, but with the slight change to the code "tables/table/field/pk['{0}']" Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.