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

  • Thread starter Ramon F Herrera
  • Start date
R

Ramon F Herrera

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
 
A

Alain Ketterlin

[...]
/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.
 
R

Ramon F Herrera

[...]
/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
 
R

Ramon F Herrera

[...]
/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
 
J

Joe Kesselman

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."
 
R

Ramon F Herrera

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
 
R

Ramon F Herrera

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
 
A

Alain Ketterlin

Ramon F Herrera said:
[...]
/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.
 
S

Simon Wright

Ramon F Herrera said:
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?
 
R

Ramon F Herrera

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
 
R

Ramon F Herrera

[...]
/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
 

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

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top