tags:

views:

291

answers:

3

For example i have this xml. I need to get value of parameter val of tag foo with id="two"

<top>
    <sub id="one">
        <foo id="two" val="bar" />
        sometext
    </sub>
</top>

Whis this query (using Qt QXmlQuery):

doc('test.xml')/top/sub[@id='one']/foo[@id='two']/<p>{@val}</p>

I receive <p val="bar"/>, but I need only text "bar" without any tags. I tried to remove <p> and </p> and receive syntax error, unexpected {

How can i get parameter value without any tags?

A: 
doc('test.xml')/top/sub[@id='one']/foo[@id='two']/@val
David Sauter
Thank you for answer! But it not works with QXmlQuery. Internal serializer of QXmlQuery can process only valid XML (with tags, etc.) But @val returns only plain text (Actually what i need) and serializer can't process it.For tag content (`sometext` in example) i use `text()`:`doc('test.xml')/top/sub[@id='one']/foo[@id='two']/text()` to receive plain text, but for tag parameters it doesn't work. :(
uni
+2  A: 

If you try to serialize just an attribute you will get an error. You may be better off just retrieving the value of the attribute:

doc('test.xml')/top/sub[@id='one']/foo[@id='two']/@val/data(.)
Oliver Hallam
A: 

Hi Sorry a bit late in the day... try

data(doc('/db/test/test.xml')/top/sub[@id='one']/foo[@id='two']/@val)

which returns just the text value of the attribute

richard