470,594 Members | 1,120 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

XPath syntax Validation/Help?

I am attempting to use XPath to query for a specific node
in the sample XML I've provided below.

I'm unsure of the exact XPath syntax, but I believe I
need the following query to get the proper node where the
node value contains a specific value:

/FYIFORM/TEMPLATEINFO/FIELD[@ID = "ODM_NAME"] = "THE FORM
I WANT"

Once I get a reference to this 'field' node, I can then
use the [MyNode.Parent] approach to navigate up to the
parent node. It's tHe 'DKey' attribute on that parent
node that I'm actually after. Also, I know there's
something like ANCESTOR:: or something that would make my
returned reference actually be the parent.. either
approach is fine by me... I was especially unsure of the
ancestor approach/syntax...

Once I have obtained the DKey for the template, I can
then use an additional XPath query to get
the 'SEARCHCLASS' field for that template who's value I
also require.

I believe the second XPath query I'll need is as follows:

/FYIFORM/TEMPLATEINFO[@DKEY=3110]/FIELD[@ID
= "SEARCHCLASS"]

Then the Node.Value here should be the actual 'search
class' I'm looking for...

Thanks for any help you can provide!

The sample XML:

<FYIFORM>
<TEMPLATEINFO DKEY="3110">
<FIELD ID="ODM_NAME">THE FORM I WANT</FIELD>
<FIELD ID="ODM_COMMENTS"></FIELD>
<FIELD ID="ODM_TITLE"></FIELD>
<FIELD ID="ODM_SUBJECT"></FIELD>
<FIELD ID="SEARCHCLASS">SearchClass1</FIELD>
</TEMPLATEINFO>
<TEMPLATEINFO DKEY="2835">
<FIELD ID="ODM_NAME">SOME OTHER FORM</FIELD>
<FIELD ID="ODM_COMMENTS"></FIELD>
<FIELD ID="ODM_TITLE"></FIELD>
<FIELD ID="ODM_SUBJECT"></FIELD>
<FIELD ID="SEARCHCLASS">SearchClass2</FIELD>
</TEMPLATEINFO>
</FYIFORM>

Nov 12 '05 #1
1 1896
Brad Hehe wrote:
I am attempting to use XPath to query for a specific node
in the sample XML I've provided below.

I'm unsure of the exact XPath syntax, but I believe I
need the following query to get the proper node where the
node value contains a specific value:

/FYIFORM/TEMPLATEINFO/FIELD[@ID = "ODM_NAME"] = "THE FORM
I WANT"

Once I get a reference to this 'field' node, I can then
use the [MyNode.Parent] approach to navigate up to the
parent node. It's tHe 'DKey' attribute on that parent
node that I'm actually after. Also, I know there's
something like ANCESTOR:: or something that would make my
returned reference actually be the parent.. either
approach is fine by me... I was especially unsure of the
ancestor approach/syntax...

Once I have obtained the DKey for the template, I can
then use an additional XPath query to get
the 'SEARCHCLASS' field for that template who's value I
also require.

I believe the second XPath query I'll need is as follows:

/FYIFORM/TEMPLATEINFO[@DKEY=3110]/FIELD[@ID
= "SEARCHCLASS"]

Then the Node.Value here should be the actual 'search
class' I'm looking for...


Isn't this is a shorter way:

/FYIFORM/TEMPLATEINFO[FIELD[@ID="ODM_NAME"] ="THE FORM I
WANT"]/FIELD[@ID="SEARCHCLASS"]

or even
/FYIFORM/TEMPLATEINFO[FIELD[@ID="ODM_NAME"] ="THE FORM I
WANT"]/FIELD[@ID="SEARCHCLASS"]/text()
to get text value directly.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Franck | last post: by
2 posts views Thread by Locusta | last post: by
9 posts views Thread by David Thielen | last post: by
7 posts views Thread by Tim Hallwyl | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.