0

I have this xml:

<Forms>
<Form ID="5472" TemplateID="588" DocType="1" FileName="635073174134006854.pdf" HiulActType="1"/>
<Form ID="5472" TemplateID="2619" DocType="1" FileName="635073174134006854.pdf" HiulActType="1"/>
HiulDocCode="414" TimeStamp="2013-06-20-09_29_13_317421">
</Forms>

I want to get the attribute HiulActType of the form which has attribte TemplateID = 2619.

I tried:

`//Form[@TemplateID='2619']/@HiulActType/text()

Wont work.`

1
  • There is only the text() function superfluous. Therefor //Form[@TemplateID='2619']/@HiulActType should do (if there is not typo). If not, there is probably a namespace issue with your xml which you are hiding. Commented Jun 26, 2013 at 7:03

1 Answer 1

2

Attribute nodes do not have text node children. Just drop the /text() from your path expression.

I'm seeing more and more people sprinkle /text() into their XPath expressions as a kind of magic fairy dust. It's almost always superfluous and often plain wrong. If you really want to force conversion of the result to a string rather than relying on automatic conversion, don't use /text(), use the string() function.

Sign up to request clarification or add additional context in comments.

Comments

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.