aj*****@googlemail.com wrote:
Hi folks,
I am new to XML. I came across the following location path expressions:
(i) /*/*
(ii) /quotelist/quotation
can anyone explain me the nodeset for the above two path expressions
Assuming this is XPath, then
(i) means "any element which is a child of [any] root element".
In your sample document, it will return a nodeset of three
quotation elements.
(ii) means "all quotation elements which are children of the
quotelist root element". The effect on your sample document
is identical to (i).
According to whatever DTD or schema you use, there may of course be
other element types which are permitted within quotelist. These will
be included in the nodeset by (i) but not by (ii).
Equally, your application may allow other element types to be the
root element of different subtypes of document. In that case, (i)
may be more appropriate than (ii) in some circumstances. For example,
if you output a document consisting of a single quotation, eg:
<quotation style="wise" id="q1">
<textExpect nothing; be ready for everything. </text>
<sourceSamurai Chant </source>
</quotation>
then (i) will return a nodeset consisting of a text element and a source
element, but (ii) will return an empty nodeset.
As a matter of style and efficiency, you should avoid using leading and
trailing spaces in element types containing PCDATA or mixed content, in
case later processing systems are unaware of it (the source above, for
example, is NOT equal to "Samurai Chant" but " Samurai Chant " with the
extra spaces.
///Peter
--
XML FAQ:
http://xml.silmaril.ie/
relating to the following XML document:
<quotelist>
<quotation style="wise" id="q1">
<textExpect nothing; be ready for everything. </text>
<sourceSamurai Chant </source>
</quotation>
<quotation style="political" id="q2">
<textIf one morning I walked on top of the water across the
Potomac
River, teh headline that afternoon would read "President
can't Swim".</text>
<sourceXYZ </source>
</quotation>
<!-- This is a comment -->
<quotation style="silly" id="q3">
<textWhat if the hokey-pokey IS what it's all about?
</text>
</quotation>
</quotelist>
Thanks in anticipation.
Regards,
Asrar