Help me with XPATH expression

Discussion in 'XML' started by ajkadri@googlemail.com, Oct 1, 2006.

  1. Guest

    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
    , Oct 1, 2006
    #1
    1. Advertising

  2. 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

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Oct 1, 2006
    #2
    1. Advertising

  3. Peter Flynn Guest

    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">
    <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
    --
    XML FAQ: http://xml.silmaril.ie/

    > 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
    >
    Peter Flynn, Oct 1, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,970
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,403
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    521
  4. goog
    Replies:
    0
    Views:
    506
  5. GIMME
    Replies:
    3
    Views:
    11,954
    vforvikash
    Dec 29, 2008
Loading...

Share This Page