473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

XPath query problem.

Hi.
I'm trying to locate one node in the following XML:
<?xml version="1.0" encoding="utf-8" ?>
<ROUTINES>
<ROUTINE name="TA14">
<METHOD name="1">
<DEBET>
<SUBROUTINE name="1401"></SUBROUTINE>
<SUBROUTINE name="1402"></SUBROUTINE>
<SUBROUTINE name="1408"></SUBROUTINE>
</DEBET>
<CREDIT>
<SUBROUTINE name="1403"></SUBROUTINE>
<SUBROUTINE name="1404"></SUBROUTINE>
<SUBROUTINE name="1409"></SUBROUTINE>
</CREDIT>
</METHOD>
</ROUTINE>
</ROUTINES>

Why doesn't the following query find the subroutine node with attribute
name=TA1401

tempNode =
mVoRoutines.SelectSingleNode("ROUTINES/ROUTINE[@name='TA14']/METHOD[@name='1']/DEBET/SUBROUTINE[@name='1401']")

I can find it's parent node by:
tempNode =
mVoRoutines.SelectSingleNode("ROUTINES/ROUTINE[@name='TA14']/METHOD[@name='1']/DEBET")

/Johan
Nov 12 '05 #1
1 1461


Johan Smidje wrote:

I'm trying to locate one node in the following XML:
<?xml version="1.0" encoding="utf-8" ?>
<ROUTINES>
<ROUTINE name="TA14">
<METHOD name="1">
<DEBET>
<SUBROUTINE name="1401"></SUBROUTINE>
<SUBROUTINE name="1402"></SUBROUTINE>
<SUBROUTINE name="1408"></SUBROUTINE>
</DEBET>
<CREDIT>
<SUBROUTINE name="1403"></SUBROUTINE>
<SUBROUTINE name="1404"></SUBROUTINE>
<SUBROUTINE name="1409"></SUBROUTINE>
</CREDIT>
</METHOD>
</ROUTINE>
</ROUTINES>

Why doesn't the following query find the subroutine node with attribute
name=TA1401

tempNode =
mVoRoutines.SelectSingleNode("ROUTINES/ROUTINE[@name='TA14']/METHOD[@name='1']/DEBET/SUBROUTINE[@name='1401']")


Using the following C# .NET 1.1 code an element node is found:

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"test2004092101.xml");
XmlElement subroutine = (XmlElement)
xmlDocument.SelectSingleNode("ROUTINES/ROUTINE[@name='TA14']/METHOD[@name='1']/DEBET/SUBROUTINE[@name='1401']");
if (subroutine != null) {
Console.WriteLine("Found {0}.", subroutine);
}
else {
Console.WriteLine("No node found.");
}

If your code doesn't find the node I assume that mVoRoutines is not the
document node (root node).

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

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

Similar topics

1
by: Chris | last post by:
Hi all, I have recently started working with the new XML functionality in PHP5, but I am running into a few problems. Specifically, I am using an Xpath query to try and pull out the data in...
6
by: 0wl | last post by:
Hi, I am trying to get the value of child from xmlstr = """<p:root xmlns:p="http://tempuri.org/string"><p:child DataType="String">Hellpppp</p:child></p:root>""" using...
8
by: Terry P | last post by:
Are there any tools (java classes, tag libraries) which can translate xpath statements into a SQL query? Given an xpath query which has a predicate that filters node values or attributes, I want...
1
by: david_b_mcconnell | last post by:
Hi, I am having a problem using XPath when I validate Xml documents with a schema. Basically what happens is that an XPath query doesn't return the nodes I require if a schema is used to validate...
7
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
6
by: dotnetnoob | last post by:
i would like to know how i can build xpath expression dynamiclly. let's say i have a following xml file: <EventEnrollment InstanceNumber = "675"> <EventSource> <ObjectReference...
2
by: Riki | last post by:
I'm stuck with an XPath query to produce a TreeView. From the data below, I want to select all the score elements having an IdIn of 2018, ***including their ancestors***. With the result, I want...
3
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
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...

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.