xml - Unclear use of // in XPath -
let's @ following xml file:
<a> <b w="w"> <b1 x="x" /> <b2 y="y" /> </b> </a>
the following xpath query returns elements b1
, b2
:
/*/*//*
from conclude //*
means select elements descendants of b
not including b
itself.
however following xpath query returns attributes w
, x
, y
:
/*/*//@*
so conclude //@*
means select attributes appear in descendants of b
including b
itself.
how work? //
work differently elements vs attributes, or there i'm missing?
//
short /descendant-or-self::node()/
/*
meanwhile identifies child nodes current position.
starting root, /*/*//
therefore moves <a>
(child of root) , <b>
(all children of <a>
being single <b>
) , selects descendant-or-self::node()
, say, <b>
, <b1>
, <b2>
.
it's starting point of <b>
, <b1>
, <b2>
matched /*/*//
2 paths differ.
/*/*//*
matches child nodes of nodes. since <b1>
, <b2>
don't have child nodes, matches child nodes of <b>
: <b1>
, <b2>
.
/*/*//@*
matches attributes of nodes. since <b>
, <b1>
, <b2>
have attributes, of attributes matched.
from conclude
//*
means select elements descendants ofb
not includingb
itself.
yes, indirectly. means "select elements descendants of b
including b
itself, , then find children". amounts "all descendants of b
not b
" went through "including b
" there.
Comments
Post a Comment