开发者

How to get tag parameter value with XQuery

开发者 https://www.devze.com 2022-12-24 00:32 出处:网络
For example i have this xml. I need to get value of parameter val of tag foo with id=\"two\" <top>

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?


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(.)


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


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

精彩评论

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

关注公众号