Help me with XPATH expression

A

ajkadri

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
relating to the following XML document:

<quotelist>
<quotation style="wise" id="q1">
<text> Expect nothing; be ready for everything. </text>
<source> Samurai Chant </source>
</quotation>

<quotation style="political" id="q2">
<text> If one morning I walked on top of the water across the
Potomac
River, teh headline that afternoon would read "President
can't Swim".</text>
<source> XYZ </source>
</quotation>
<!-- This is a comment -->
<quotation style="silly" id="q3">
<text> What if the hokey-pokey IS what it's all about?
</text>

</quotation>

</quotelist>

Thanks in anticipation.

Regards,
Asrar
 
J

Joe Kesselman

This is pretty darned basic. If this is the level of information you
need, I *REALLY* recommend that you read an XPath tutorial or two,
because otherwise we're going to wind up spoon-feeding you the
equivalent of one. One good collection of tutorials and articles can be
found at
http://www.ibm.com/xml
 
P

Peter Flynn

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">
<text> Expect nothing; be ready for everything. </text>
<source> Samurai 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

anybody help me 1
Help with imagemap! 8

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top