473,799 Members | 2,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 SelectSingleNod e 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 3590


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 SelectSingleNod e 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 SelectSingleNod e 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 SelectSingleNod e 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
8718
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 System.IO.StringReader(node.InnerText); xdoc.Load(sr);
1
6824
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. The problem is that I'm getting multiple processing instructions and multiple root elements in my xml file when I use a FileStream. Here is an example: test_1.xml contains: <?xml version="1.0" encoding="utf-8"?> <root>
2
6211
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 XmlNodeList nodeList = doc1.SelectNodes("//row"); foreach (XmlNode nodeCode in nodeList) { sb.Append(nodeCode.OuterXml);
7
4905
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: Value of type System.xml.xmldocument cannot be converted to System.IO.textreader. I would think this is possible to do. Code snippet is below:
8
6166
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 required for databinding. Am happy to work with the XmlNodeList but I can't shake the feeling I'm missing something <blush> Thanks, Pete
3
1669
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> <TableColumn><Width>1.5in</Width></TableColumn> <TableColumn><Width>1.5in</Width></TableColumn> <TableColumn><Width>1.5in</Width></TableColumn> </TableColumns>
2
1633
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 existing document to load but want to create one from scratch. How can I do this? Just a simple example. I am sure I am missing something obvious to everyone but me..
4
18189
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 in the system, XML like this is created
1
2062
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
3884
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 XMLDocument and my first question is why does this work? XmlNode neNode; neNode = myHFCService.GetPOs(); DataSet myds = new DataSet();
0
9540
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10250
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
10222
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
10026
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...
0
6805
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
5463
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
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.