1

I have simple XML structure like this:

<project>
  <frame>
    <object type="Circle" radius="5"/>
    <object type="Square" side ="4"/>
  </frame>
</project>

What path string should I use(XPath 1.0) to receive radius attribute's value of object, which type attribute is equal to "Circle".

/project/frame/object[@type="Circle"]/@radius

Is it correct?

Edited: Yes, it is really correct, I've checked it using tools, that was adviced me in comments. But the string returned is:

 radius="5"

Are there any approach to receice only attribute value - "5"??

vard
  • 2,142
  • 4
  • 30
  • 40
  • Which programming language are you using? – Stanley Dec 03 '12 at 13:08
  • 1
    It certainly looks correct to me. Do you get an error from your toolset or not the right answer? What are you doing with the XPath expression? – Christopher Creutzig Dec 03 '12 at 13:10
  • I'm using C. I want to write XPath based XML parsing interface for ARM-core microcontroller. But I think programming language doesn't matter for this question. – vard Dec 03 '12 at 13:11
  • 1
    Your xpath is good; your xml is less so (your `object` elements are unclosed) – paul Dec 03 '12 at 13:12
  • @Christopher Creutzig, I just have little misunderstanding about XPath syntax. – vard Dec 03 '12 at 13:12
  • 1
    Get yourself some tool that handles them (xml starlet, saxon, your browser, …) and play around with them then. :-) – Christopher Creutzig Dec 03 '12 at 13:14
  • 1
    [This might also be helpful](http://stackoverflow.com/questions/688323/is-there-an-online-tester-for-xpath-selectors) – predi Dec 03 '12 at 13:23

1 Answers1

0

Try this:

doc("c:\temp\temp.xml")
/data(/project/frame/object[@type="Circle"]/@radius)
wBob
  • 13,710
  • 3
  • 20
  • 37