I guess XPath is not as straightforward as I thought...

Discussion in 'XML' started by Ramon F Herrera, Jun 6, 2012.

  1. A few years back, after having developed my very own implementation of
    an XML retrieval function, I discovered that I had just reinvented the
    wheel: it is known as XPath. My wheel only handled the simplest
    format, though.

    I have grown comfortable with several XPath implementations, until
    now, that is.

    Now I am stuck with many tables which are very similar, and I get too
    many hits. The items that I need are easily retrieved by these paths:

    /root/table[9]/intermediate_joints/joint_label
    /root/table[10]/intermediate_joints/joint_label

    Since those numbers (9 and 10) only work for one XML file, how do I
    determine them in a general way?

    The following xpath hits those tables, but I need to retrieve the
    values 9 and 10.

    /root/table[@tagname='intermediate_joints']

    Is this what XQuery is for? (I am not familiar with it)???

    TIA,

    -Ramon

    -------------
    Note: I use C++, Xerces-C and Xqilla
    Ramon F Herrera, Jun 6, 2012
    #1
    1. Advertising

  2. Ramon F Herrera <> writes:

    [...]
    > /root/table[9]/intermediate_joints/joint_label
    > /root/table[10]/intermediate_joints/joint_label
    >
    > Since those numbers (9 and 10) only work for one XML file, how do I
    > determine them in a general way?
    >
    > The following xpath hits those tables, but I need to retrieve the
    > values 9 and 10.
    >
    > /root/table[@tagname='intermediate_joints']


    Something like this should do:

    count(/root/table[@...]/preceding-sibling::table)

    -- Alain.
    Alain Ketterlin, Jun 6, 2012
    #2
    1. Advertising

  3. On Jun 6, 12:22 pm, Alain Ketterlin <-strasbg.fr>
    wrote:
    > Ramon F Herrera <> writes:
    >
    > [...]
    >
    > > /root/table[9]/intermediate_joints/joint_label
    > > /root/table[10]/intermediate_joints/joint_label

    >
    > > Since those numbers (9 and 10) only work for one XML file, how do I
    > > determine them in a general way?

    >
    > > The following xpath hits those tables, but I need to retrieve the
    > > values 9 and 10.

    >
    > > /root/table[@tagname='intermediate_joints']

    >
    > Something like this should do:
    >
    > count(/root/table[@...]/preceding-sibling::table)
    >
    > -- Alain.


    Thanks, Alain. I tried it:

    count(/root/table[@tagname='intermediate_joints']/preceding-
    sibling::table)

    but I only got one table, the output of the path above is 9.

    -Ramon
    Ramon F Herrera, Jun 6, 2012
    #3
  4. On Jun 6, 12:22 pm, Alain Ketterlin <-strasbg.fr>
    wrote:
    > Ramon F Herrera <> writes:
    >
    > [...]
    >
    > > /root/table[9]/intermediate_joints/joint_label
    > > /root/table[10]/intermediate_joints/joint_label

    >
    > > Since those numbers (9 and 10) only work for one XML file, how do I
    > > determine them in a general way?

    >
    > > The following xpath hits those tables, but I need to retrieve the
    > > values 9 and 10.

    >
    > > /root/table[@tagname='intermediate_joints']

    >
    > Something like this should do:
    >
    > count(/root/table[@...]/preceding-sibling::table)
    >
    > -- Alain.


    Actually, I don't really needs those indices (9 and 10). I can "grab"
    each of the 2 desired tables, with this expression:

    /root/table[@tagname='intermediate_joints']

    and next I need to perform an XPath query rooted at each of them:
    That, I don't know how to do...

    -Ramon
    Ramon F Herrera, Jun 6, 2012
    #4
  5. On 6/6/2012 2:05 PM, Ramon F Herrera wrote:
    > and next I need to perform an XPath query rooted at each of them:
    > That, I don't know how to do...


    You generally can't perform an XPath _rooted_ at a given node. You can
    perform one relative to a given node.

    If you told us what you were actually trying to accomplish -- gave us a
    sample document and pointed out what you want and what criteria
    distinguish it from other points in the document -- that would actually
    be easier for us to help you with.


    --
    Joe Kesselman,
    http://www.love-song-productions.com/people/keshlam/index.html

    {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
    /\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
    Joe Kesselman, Jun 6, 2012
    #5
  6. On Jun 6, 1:16 pm, Joe Kesselman <>
    wrote:
    > On 6/6/2012 2:05 PM, Ramon F Herrera wrote:
    >
    > > and next I need to perform an XPath query rooted at each of them:
    > > That, I don't know how to do...

    >


    > You generally can't perform an XPath  _rooted_ at a given node.
    > You can perform one relative to a given node.


    That is what I meant.

    I was thinking of the "chroot()" Unix system call.

    -Ramon
    Ramon F Herrera, Jun 6, 2012
    #6
  7. On Jun 6, 1:16 pm, Joe Kesselman <>
    wrote:
    > On 6/6/2012 2:05 PM, Ramon F Herrera wrote:
    >
    > > and next I need to perform an XPath query rooted at each of them:
    > > That, I don't know how to do...

    >
    > You generally can't perform an XPath  _rooted_ at a given node. You can
    > perform one relative to a given node.
    >
    > If you told us what you were actually trying to accomplish -- gave us a
    > sample document and pointed out what you want and what criteria
    > distinguish it from other points in the document -- that would actually
    > be easier for us to help you with.


    Great!

    Is there a location where I can e-mail the XML file to you?

    -Ramon
    Ramon F Herrera, Jun 6, 2012
    #7
  8. Ramon F Herrera <> writes:

    > On Jun 6, 12:22 pm, Alain Ketterlin <-strasbg.fr>
    > wrote:
    >> Ramon F Herrera <> writes:
    >>
    >> [...]
    >>
    >> > /root/table[9]/intermediate_joints/joint_label
    >> > /root/table[10]/intermediate_joints/joint_label

    >>
    >> > Since those numbers (9 and 10) only work for one XML file, how do I
    >> > determine them in a general way?

    >>
    >> > The following xpath hits those tables, but I need to retrieve the
    >> > values 9 and 10.

    >>
    >> > /root/table[@tagname='intermediate_joints']

    >>
    >> Something like this should do:
    >>
    >> count(/root/table[@...]/preceding-sibling::table)
    >>
    >> -- Alain.

    >
    > Actually, I don't really needs those indices (9 and 10). I can "grab"
    > each of the 2 desired tables, with this expression:
    >
    > /root/table[@tagname='intermediate_joints']


    You just told us that you needed these numbers...

    > and next I need to perform an XPath query rooted at each of them:
    > That, I don't know how to do...


    Yes, XPath has a notion of context (see XPath recommandation). How you
    set the context depends on what you're using to process your query.

    -- Alain.
    Alain Ketterlin, Jun 6, 2012
    #8
  9. Ramon F Herrera

    Simon Wright Guest

    Ramon F Herrera <> writes:

    > A few years back, after having developed my very own implementation of
    > an XML retrieval function, I discovered that I had just reinvented the
    > wheel: it is known as XPath. My wheel only handled the simplest
    > format, though.
    >
    > I have grown comfortable with several XPath implementations, until
    > now, that is.
    >
    > Now I am stuck with many tables which are very similar, and I get too
    > many hits. The items that I need are easily retrieved by these paths:
    >
    > /root/table[9]/intermediate_joints/joint_label
    > /root/table[10]/intermediate_joints/joint_label
    >
    > Since those numbers (9 and 10) only work for one XML file, how do I
    > determine them in a general way?
    >
    > The following xpath hits those tables, but I need to retrieve the
    > values 9 and 10.
    >
    > /root/table[@tagname='intermediate_joints']


    Then wouldn't

    /root/table[@tagname='intermediate_joints']/intermediate_joints/joint_label

    do the trick?
    Simon Wright, Jun 6, 2012
    #9
  10. On Jun 6, 2:02 pm, Simon Wright <> wrote:
    > Ramon F Herrera <> writes:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > A few years back, after having developed my very own implementation of
    > > an XML retrieval function, I discovered that I had just reinvented the
    > > wheel: it is known as XPath. My wheel only handled the simplest
    > > format, though.

    >
    > > I have grown comfortable with several XPath implementations, until
    > > now, that is.

    >
    > > Now I am stuck with many tables which are very similar, and I get too
    > > many hits. The items that I need are easily retrieved by these paths:

    >
    > > /root/table[9]/intermediate_joints/joint_label
    > > /root/table[10]/intermediate_joints/joint_label

    >
    > > Since those numbers (9 and 10) only work for one XML file, how do I
    > > determine them in a general way?

    >
    > > The following xpath hits those tables, but I need to retrieve the
    > > values 9 and 10.

    >
    > > /root/table[@tagname='intermediate_joints']

    >


    > Then wouldn't
    >
    >   /root/table[@tagname='intermediate_joints']/intermediate_joints/

    joint_label
    >
    > do the trick?


    That is a very good question... Already tried it.

    The problem is that deeper down the tables become different. That path
    "joins" 2 tables that I need separated.

    -Ramon
    Ramon F Herrera, Jun 6, 2012
    #10
  11. On Jun 6, 1:46 pm, Alain Ketterlin <-strasbg.fr>
    wrote:
    > Ramon F Herrera <> writes:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > On Jun 6, 12:22 pm, Alain Ketterlin <-strasbg.fr>
    > > wrote:
    > >> Ramon F Herrera <> writes:

    >
    > >> [...]

    >
    > >> > /root/table[9]/intermediate_joints/joint_label
    > >> > /root/table[10]/intermediate_joints/joint_label

    >
    > >> > Since those numbers (9 and 10) only work for one XML file, how do I
    > >> > determine them in a general way?

    >
    > >> > The following xpath hits those tables, but I need to retrieve the
    > >> > values 9 and 10.

    >
    > >> > /root/table[@tagname='intermediate_joints']

    >
    > >> Something like this should do:

    >
    > >> count(/root/table[@...]/preceding-sibling::table)

    >
    > >> -- Alain.

    >
    > > Actually, I don't really needs those indices (9 and 10). I can "grab"
    > > each of the 2 desired tables, with this expression:

    >
    > > /root/table[@tagname='intermediate_joints']

    >


    > You just told us that you needed these numbers...


    I *could* use the numbers, provided that they are indices. The count()
    function seems to count number of hits. In fact, I am confused with
    that 'count()' function.

    -Ramon
    Ramon F Herrera, Jun 6, 2012
    #11
  12. On 6/6/2012 2:33 PM, Ramon F Herrera wrote:
    > Is there a location where I can e-mail the XML file to you?


    Keep the discussion on the newsgroup, please. That way more of us can
    contribute to the answer, and the answer helps more people.


    --
    Joe Kesselman,
    http://www.love-song-productions.com/people/keshlam/index.html

    {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
    /\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
    Joe Kesselman, Jun 7, 2012
    #12
    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. Anna
    Replies:
    0
    Views:
    507
  2. Vasileios Zografos
    Replies:
    5
    Views:
    439
    Vasileios Zografos
    Jul 1, 2003
  3. The alMIGHTY N
    Replies:
    1
    Views:
    612
    Joris Gillis
    Feb 9, 2007
  4. news.microsoft.com
    Replies:
    2
    Views:
    418
    Alan Silver
    Jul 22, 2007
  5. taj sha
    Replies:
    0
    Views:
    684
    taj sha
    Aug 14, 2012
Loading...

Share This Page