Hello, not sure i am using xpath correctly. have the following trivial
xml.
<?:xml version="1.0" standalone="yes" ?>
<top attr="1">
content1
content2
<inner id="first" day="friday">
content3
</inner>
</top>
if i want the content of the tag "inner", do i need either of these or
note yeu don't want the content of the tag inner (the content of the
start tag is "inner id="first" day="friday"" and the content of the end
tag is "/inner", you want the content of the element (it's best not to
confuse "tag" and "element" when working with xpath, as xpath has no
access to the tags.
something else?
/top/inner/child::text()
that's the same as
top/inner/text()
as child is the default axis, and selects the text node with content3
(and some white space) note that it's usially better to just use
/top/inner
as the string value of the element is all its text descendents. If you
explictly use text() then it will most likely fail if for example anyone
adds a comment
<inner>
<!-- here -->
content3
</inner>
as then the first text node is _just_ the white space before the comment
(and most xpath1 string functions only operate on the first node if mre
than one is selected)
/top/inner/*[node()=text()]
inner* selects all the element node children of inner but in your case
inner has no element children so this will be empty (even without the
filter). The filter [node()=text()] is true if any child node is equal
to any child text node. since the right hand side is a subset f the left
hand side this is always true if text() is non empty, ie if there is a
text node. so *[node()=text()] is *[text()] and selects all elements
that have text node children.
David