Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XQuery: Return value of an element rather the element itself

Tags:

I have an XML document that contains the following

... <foo>abc</foo> ... 

If I evaluate

return $xml//foo 

I get back

<foo>abc</foo> 

Is there any way to get just abc instead?

like image 500
kpozin Avatar asked Jul 20 '09 18:07

kpozin


1 Answers

Yes, you want the text() function for selecting the child text:

return $xml/text() 

Be careful if you will have nested tag structure inside $xml though, because this will only go one level deep for text nodes. If you want all of the text nodes together, stripping out other XML structure, this will do arbitrarily deep:

return $xml//text() 
like image 72
Harold L Avatar answered Sep 22 '22 14:09

Harold L