473,407 Members | 2,629 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,407 software developers and data experts.

Xml: Finding the right node to modify

Hey there,

I'm having trouble finding the right XPath expression. The XML file I'm
parsing contains an element Heads which contains sereveral Head elements.
These Head elements have several Row sub-elements.

Heads ->(0..*)Head -> ...subelements... -> (0..*)Row

The problem I have is that I find the wrong Row elements, ie I always find
the FIRST Row element inside the complete Xml document. This is probably
caused by a bad XPath expression I gave :) Can you help me?

What I do is the following. Each Head has an index element (Index), each Row
also has an Index element. First I try to find the Head. I start searching
from the Heads node within the Xml file:

XmlNode headsNode = xmlDoc.SelectSingleNode( "//Heads" );
XmlNode baseHeadNode = headsNode.SelectSingleNode( "//Head[Index=i]" );
XmlNode rowNode = baseHeadNode.SelectSingleNode( "//Row[Index=0]" );

The i is a number between 0 and #heads-1. The last statement always gives me
the first Row with Index 0 inside the whole XML file, NOT the Row with Index
0 that is found under Head with Index i.

What is wrong with my XPath expression?
--
Tom Tempelaere.
Nov 16 '05 #1
2 4720
Hi again,

I found a solution, but I'm still wondering why the original code I posted
does not work.

I find the correct Row elements if I use the following code instead:

XmlNode headsNode = xmlDoc.SelectSingleNode( "//Heads" );
XmlNode rowNode = headsNode.SelectSingleNode (
"//Head[Index=i]//Row[Index=0]"
);

I fail to see what is so different between this way of looking up the Row
elements, and the way I posted earlier...

Thanks,
Tom T.

"TT (Tom Tempelaere)" wrote:
Hey there,

I'm having trouble finding the right XPath expression. The XML file I'm
parsing contains an element Heads which contains sereveral Head elements.
These Head elements have several Row sub-elements.

Heads ->(0..*)Head -> ...subelements... -> (0..*)Row

The problem I have is that I find the wrong Row elements, ie I always find
the FIRST Row element inside the complete Xml document. This is probably
caused by a bad XPath expression I gave :) Can you help me?

What I do is the following. Each Head has an index element (Index), each Row
also has an Index element. First I try to find the Head. I start searching
from the Heads node within the Xml file:

XmlNode headsNode = xmlDoc.SelectSingleNode( "//Heads" );
XmlNode baseHeadNode = headsNode.SelectSingleNode( "//Head[Index=i]" );
XmlNode rowNode = baseHeadNode.SelectSingleNode( "//Row[Index=0]" );

The i is a number between 0 and #heads-1. The last statement always gives me
the first Row with Index 0 inside the whole XML file, NOT the Row with Index
0 that is found under Head with Index i.

What is wrong with my XPath expression?
--
Tom Tempelaere.

Nov 16 '05 #2
Hey,

Could it be that I had to write the lookup of the Row elements as follows?

XmlNode headsNode = xmlDoc.SelectSingleNode( "//Heads" );
XmlNode baseHeadNode = headsNode.SelectSingleNode( "//Head[Index=i]" );
XmlNode rowNode = baseHeadNode.SelectSingleNode( ".//Row[Index=0]" );

So let lookup of Row elements start explicitely from the Head element
context? I guess so...

Thanks,
Tom T.

"TT (Tom Tempelaere)" wrote:
Hi again,

I found a solution, but I'm still wondering why the original code I posted
does not work.

I find the correct Row elements if I use the following code instead:

XmlNode headsNode = xmlDoc.SelectSingleNode( "//Heads" );
XmlNode rowNode = headsNode.SelectSingleNode (
"//Head[Index=i]//Row[Index=0]"
);

I fail to see what is so different between this way of looking up the Row
elements, and the way I posted earlier...

Thanks,
Tom T.

"TT (Tom Tempelaere)" wrote:
Hey there,

I'm having trouble finding the right XPath expression. The XML file I'm
parsing contains an element Heads which contains sereveral Head elements.
These Head elements have several Row sub-elements.

Heads ->(0..*)Head -> ...subelements... -> (0..*)Row

The problem I have is that I find the wrong Row elements, ie I always find
the FIRST Row element inside the complete Xml document. This is probably
caused by a bad XPath expression I gave :) Can you help me?

What I do is the following. Each Head has an index element (Index), each Row
also has an Index element. First I try to find the Head. I start searching
from the Heads node within the Xml file:

XmlNode headsNode = xmlDoc.SelectSingleNode( "//Heads" );
XmlNode baseHeadNode = headsNode.SelectSingleNode( "//Head[Index=i]" );
XmlNode rowNode = baseHeadNode.SelectSingleNode( "//Row[Index=0]" );

The i is a number between 0 and #heads-1. The last statement always gives me
the first Row with Index 0 inside the whole XML file, NOT the Row with Index
0 that is found under Head with Index i.

What is wrong with my XPath expression?
--
Tom Tempelaere.

Nov 16 '05 #3

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

Similar topics

0
by: David Gersic | last post by:
I'm working with an HR system and trying to deal with an XML document that contains a bunch of personal data (unique to the person) and one or more sets of job data (a person can be hired more than...
5
by: reddy | last post by:
I am trying to insert a node into an XMLFile. using XMLTextwriter. My Question is Is it possible to do without using XMLDocument. Because its loading all the the file into memory. I just want to...
3
by: Uday | last post by:
Hello all, I have a XML file of 10 MB, I do not want to load this file in Memory using DOM,I know that using SAX I can read the xml file but I want to modify this XML file. I want add, delete...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
16
by: lreames | last post by:
I am new to XML, but not ASP. I have the following XML that I load via Dim xml Set xml = Server.CreateObject("Microsoft.XMLDOM") xml.async = False xml.loadXML xmldom.xml
6
by: | last post by:
Hi, I'm steel trying to read and update my XML file with Visual Basic Express but i am unable to find the right way to read my xml file and update it if neccessary... Here is my problem :...
6
by: Lang Murphy | last post by:
I'm baaaaack... some of you answered a question I had last week. Only problem is: I'm a dope who doesn't understand most of what y'all posted. Raw noob when it comes to .Net and C#. So I'm going...
8
by: =?Utf-8?B?WVhR?= | last post by:
I want to do the multi-language program, save the language text in XML file, but how to read the specified node value? the xml is below, for example, i want to get the value(AAA content) that named...
3
by: siikworm | last post by:
Hi, I'm having a couple of (possibly related) problems. 1) When I run this code as-is, I get an extra output to the screen...usually three numbers such as "559" or "205". The output appears in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.