473,701 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using XMLDocument - a newbie question

OK, so I've created and loaded an XMLDocument object.
But how do I go about using it? Specifically, how do I:
1) move to the first node (I assume I start on it when I load the XML?)
2) move to the next node (.read?)
3) move back to a previous node?

Is there a sample program somewhere to show this? (preferably VB.net)

TIA David
Aug 24 '08 #1
1 1701
DavidGB wrote:
OK, so I've created and loaded an XMLDocument object.
But how do I go about using it? Specifically, how do I:
1) move to the first node (I assume I start on it when I load the XML?)
2) move to the next node (.read?)
3) move back to a previous node?

Is there a sample program somewhere to show this? (preferably VB.net)
Assuming you have e.g.
Dim doc As New XmlDocument()
doc.Load("file. xml")
then the answers are as follows:
1) I am not sure why you want to "move" to nodes. Anyway, the first node
you have is the XmlDocument node itself. It has various properties and
methods to access its child and descendant nodes e.g.
Dim root As XmlDocument = doc.DocumentEle ment
gives you the document element (also called root element) that contains
any other elements.
doc.ChildNodes
is a collection to access all child nodes of the document. Then you can
apply the methods SelectNodes and SelectSingleNod e with XPath 1.0
expressions e.g.
Dim foo As XmlNode = doc.SelectSingl eNode("//foo")
looks for the first element named 'foo' at any level in the document.

2) If you want to process an XML document node by node in a forwards
only mode then you don't need a System.Xml.XmlD ocument, instead you use
an XmlReader and call its various Read methods. With
System.Xml.XmlD ocument you also have various properties to navigate, you
can access the FirstChild and NextSibling properties

3) If you have accessed a child node then accessing the ParentNode
property is the way back to the previous node. If you have accessed the
NextSibling property then PreviousSibling is the way back. See the
properties defined for XmlNode:
http://msdn.microsoft.com/en-us/libr...roperties.aspx

But ChildNodes/FirstChild/LastChild/NextSibling/PreviousSibling are the
"navigation al" properties the W3C Core DOM defines, the power of .NET's
DOM implementation is certainly its XPath 1.0 implementation with
SelectNodes and SelectSingleNod e. So learning XPath 1.0 certainly is a
good idea if you want to become a power user of .NET's DOM implementation.

Also note, if you use .NET 3.5 then there is LINQ to XML as a new object
model exploiting and leveraging the power of LINQ:
http://msdn.microsoft.com/en-us/library/bb387098.aspx

If you need more help then it might be best to look at a sample document
and access some nodes so consider to post a short sample and tell us
which nodes you want to access, then we can post some code.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 25 '08 #2

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

Similar topics

5
6156
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 insert in the front. My code is give below. Is it possible to do without using XMLDOcument? Dim masterDoc As String = Request.PhysicalApplicationPath & "PageViews.xml" Dim writer As XmlTextWriter = Nothing
3
9049
by: Dan | last post by:
Is there a better way to include the XML declaration than the following? XmlDeclaration dec =m_XMLDocument.CreateXmlDeclaration("1.0",string.Empty, "yes"); m_XMLDocument.InsertBefore((XmlNode)dec, (XmlNode)m_XMLDocument.DocumentElement); XmlTextWriter writer = new XmlTextWriter(m_FileName,Encoding.Default); writer.WriteRaw(m_XMLDocument.OuterXml); writer.Flush();
7
4900
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:
0
1277
by: KathyB | last post by:
Hi, I would be grateful for any guidance in how to achieve the following. I have an aspx page in which I transform an xmlDocument instance to the browser...so (as I understand it) that page contains the xmlDocument AND the transformed instance client-side in the browser. The main xml element used in this doc is a <step> element. For each step element I will create an "Anomaly" button using xsl to create an <input> button in html and...
6
7204
by: Naveed Anwar | last post by:
how a tcp server running on given uri like "soap:tcp://localhost:8080/MyReceiver" will return wsdl. In normal web service case which runs on http returns wsdl by simply appending '?wsdl' in url, but I am confused how a tcp server will do the same. plzzzzzzzzz reply :((!! thanks:) in advance
4
1924
by: Michel Verhagen | last post by:
Hi, I want to create a DTD in an XML file in memory. The XML file is created using the DOM in C#. I am new to all this, but couldn't find anything about creating DTD's using the DOM (well, I found some references but it doesn't tell me how to do what I want). Here's my code: XmlDocument xdoc = new XmlDocument();
5
3878
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();
2
2081
by: Jeff | last post by:
ASP.NET 2.0 I'm working on a asp.net 2.0 website which needs to access a database on another server via an request. This database is placed on another server which is not based on ASP.NET, but traditional ASP. The ASP.NET may access the database on the other server by requesting a .asp page with some parameters - and hte output on the .asp page was the result from the database query... So I need to access a asp page on this other server...
6
3216
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, can someone please let me know how I can read xml elements using object oriented program. I created a class to use the get and set properties however I dont know how I can pass the values from xml file to the class and use the values in my form. Thanks -- Nejadian
0
8732
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9221
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
8933
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
7822
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6567
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
4410
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...
1
3102
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2398
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2035
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.