473,803 Members | 4,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
= "SEARCHCLAS S"]

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">T HE FORM I WANT</FIELD>
<FIELD ID="ODM_COMMENT S"></FIELD>
<FIELD ID="ODM_TITLE"> </FIELD>
<FIELD ID="ODM_SUBJECT "></FIELD>
<FIELD ID="SEARCHCLASS ">SearchCla ss1</FIELD>
</TEMPLATEINFO>
<TEMPLATEINFO DKEY="2835">
<FIELD ID="ODM_NAME">S OME OTHER FORM</FIELD>
<FIELD ID="ODM_COMMENT S"></FIELD>
<FIELD ID="ODM_TITLE"> </FIELD>
<FIELD ID="ODM_SUBJECT "></FIELD>
<FIELD ID="SEARCHCLASS ">SearchCla ss2</FIELD>
</TEMPLATEINFO>
</FYIFORM>

Nov 12 '05 #1
1 2014
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
= "SEARCHCLAS S"]

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="SEARCHCLAS S"]

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1931
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
3
4547
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method should result in a NodeSet". Of course, that (sort of) makes sense to me now (I suppose just an attribute couldn't be a nodeset, but how would I go
0
1923
by: Franck | last post by:
Hi, Tryin to fill range with xml data like this in my Excel Addin '1. Add Schema oExcel.ActiveWorkbook.XmlMaps.Add(tmpDs.GetXmlSchema, oRootElement) '2. Map fields oExcel.Range(oExcel.Caller.address, Missing.Value).XPath.SetValue(oExcel.ActiveWorkbook.XmlMaps(1), "/NewDataset/Table/NAME_SECUR", Missing.Value, Missing.Value)
2
5631
by: Locusta | last post by:
Hello, I would like to use XPATH in a C program to retrieve values from XML documents. Did anyone tried this and can give me some advice? Cheers, Locusta
8
3902
by: Alan Silver | last post by:
Hello, I have a need to read the web.config file from another web site. I am trying get the value of the "theme" attribute of the "pages" node. I initially tried to do this by loading the file into an XmlDocument and using SelectSingleNode with a path like "/configuration/system.web/pages", but no matter what variation of the path I tried, this gave a null object.
9
2156
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
0
2560
by: Torsten Munkelt | last post by:
Hi, I want to write an XML-schema saying that this document <root> <edge type="special"> <target type="one"/> </edge> <edge type="special"> <target type="one"/>
7
2812
by: Tim Hallwyl | last post by:
Hi, there! As I understand the XPaht recommendation, the context node is a node; not a node-list, not XPath object -- but a single node. Now, the WS-BPEL 2.0 specification allows an XML simple type value to be the context of an XPath expression, by converting it to an XPath object -- either boolean, string or float. I do not see how this is possible, but I would like your thoughts on it.
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.