473,385 Members | 1,942 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,385 software developers and data experts.

XmlDocument and XmlNode

Siu
Hi,
I've loaded an XmlDocument from a file XML: this file has many similar
XmlNode and it is difficult to select them by using SelectSingleNode of the
object XmlDocument.

I've this question: is it possible to identify each XmlNode of the
XmlDocument by using an inner key or something like that ?
I precise that I 'm not allowed to change the file XML, therefore I can't
add any key element or attribute in each node.

Thank in advance
Nov 12 '05 #1
3 3563


Siu wrote:

I've loaded an XmlDocument from a file XML: this file has many similar
XmlNode and it is difficult to select them by using SelectSingleNode of the
object XmlDocument.

I've this question: is it possible to identify each XmlNode of the
XmlDocument by using an inner key or something like that ?
I precise that I 'm not allowed to change the file XML, therefore I can't
add any key element or attribute in each node.


If you have unique id attributes in the document then you can use
GetElementById. XPath also has an id function. But that of course
requires that you have a DTD or schema declaring attributes of type ID
and the elements have a unique id attribute value.

If you need to have keys you might want to look into XSLT, it has the
<xsl:key> instruction and the key function.

--

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

If you had a document like this:

<Root>
<Child>A</Child
<Child>A</Child>
</Root>

even though the name and content of the Child elements is the same, you can
use a positional predicate in your XPath expression to select each one in
turn: for example /Root/Child[1] and /Root/Child[2]. Will that approach not
work for your documents?

HTH

Nigel Armstrong

"Siu" wrote:
Hi,
I've loaded an XmlDocument from a file XML: this file has many similar
XmlNode and it is difficult to select them by using SelectSingleNode of the
object XmlDocument.

I've this question: is it possible to identify each XmlNode of the
XmlDocument by using an inner key or something like that ?
I precise that I 'm not allowed to change the file XML, therefore I can't
add any key element or attribute in each node.

Thank in advance

Nov 12 '05 #3
Siu
Thanks Nigel.... this is the answer I was looking for :)

"Nigel Armstrong" wrote:
Hi Siu

If you had a document like this:

<Root>
<Child>A</Child
<Child>A</Child>
</Root>

even though the name and content of the Child elements is the same, you can
use a positional predicate in your XPath expression to select each one in
turn: for example /Root/Child[1] and /Root/Child[2]. Will that approach not
work for your documents?

HTH

Nigel Armstrong

"Siu" wrote:
Hi,
I've loaded an XmlDocument from a file XML: this file has many similar
XmlNode and it is difficult to select them by using SelectSingleNode of the
object XmlDocument.

I've this question: is it possible to identify each XmlNode of the
XmlDocument by using an inner key or something like that ?
I precise that I 'm not allowed to change the file XML, therefore I can't
add any key element or attribute in each node.

Thank in advance

Nov 12 '05 #4

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

Similar topics

2
by: Ayende Rahien | last post by:
Serious problem I'm using Chris Lovett's SgmlReader class SgmlReader sr = new SgmlReader(); XmlDocument xdoc = new XmlDocument(); sr.DocType = "HTML"; sr.InputStream = new...
1
by: Shawn | last post by:
Hi. I'm using a FileStream (instead of just the path to the xml file) to load an XmlDocument. I'm doing this because I need to be able to prevent other processes to update the file I'm working on....
2
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave ...
7
by: SQLScott | last post by:
I have a Web Service in which I am trying to pass an XMLDocument as a parameter to one of the methods. I would like to use the XMLTextReader to read the XML but I am getting the following error: ...
8
by: pete | last post by:
Hi there, Can someone explain to me why I can't bind to an XmlDocument but I can bind to an XmlNodeList. It's my understanding that they both implement the IEnumerable interface which is...
3
by: Marco Rizzi | last post by:
Hi all, i'm trying to add same node to XmlDocument. This is Xml that I want to create: <TableColumns> <TableColumn><Width>1.5in</Width></TableColumn>...
2
by: Andrew Robinson | last post by:
I am attempting to create an XmlDocument object but keep getting "Object reference not set to an instance of an object" exceptions when I try to add elements or attributes. I don't have an...
4
by: Jesper Stocholm | last post by:
I have a database class that maintains data about customers i my system. The basic XML for this looks like: <Chunk> <Vendor> <Database/> </Vendor> </Chunk> When a user is to be registrered...
1
by: sridev | last post by:
hi, i am new to xml can any one plz tell me how to change the root name in a xml. <NewDataSet> - <PersonInfo> <ID>3123</ID> <Person>Mohan</Person>
5
by: GaryDean | last post by:
I have a web service method that returns an XMLDocument. The signature is: public XmlDocument GetPOs() The following client code calls this method but it accepts an XMLNode instead of an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.