Accessing and Manipulating XML Data in Microsoft .NET Framework
by Team uCertifyuCertify.com
Wednesday, 23rd August 2006
The XML Document Object Model
The XML Document Object Model commonly known as XML DOM is a representation of XML document in memory. The DOM class does the work of reading, writing, and manipulating an XML document. An XML document is a tree-structured consisting of parent and child nodes. In the above example of XML document, <StudentRecords> is the parent node and <Students> is the immediate child node. When more than one nodes are at the same level or they have the same parent node is called as sibling. There are different node types in the XML DOM. They are as under:
DOM Node Type Description
Document It is also known as the document root that behaves like a container for all nodes.
DocumentType Represents the <!DOCTYPE> node.
Element Represents the element nodes.
Attributes Represents the attributes of an element node.
Comment Represents the comment nodes.
Text Represents the text that belongs to a particular node.
Document It is also known as the document root that behaves like a container for all nodes.
DocumentType Represents the <!DOCTYPE> node.
Element Represents the element nodes.
Attributes Represents the attributes of an element node.
Comment Represents the comment nodes.
Text Represents the text that belongs to a particular node.
The XmlDocument object that is derived from the XmlNode class represents the root node or the document node. The XmlDocument class performs tasks such as loading and saving XML documents and is used to access all the nodes in the document. The XmlDocument object consists of Load, LoadXml and Save methods that loads and saves XML documents. The following code snippet written in Visual Basic .NET shows how to load an XML DOM using Load method:
Imports System
Imports System.IO
Imports System.Xml
Module Module1
Sub Main()
Dim myDoc As New XmlDocument()
MyDoc.Load("students.xml")
Console.WriteLine(myDoc.InnerXml.ToString)
Console.ReadLine()
End Sub
End Module
Imports System.IO
Imports System.Xml
Module Module1
Sub Main()
Dim myDoc As New XmlDocument()
MyDoc.Load("students.xml")
Console.WriteLine(myDoc.InnerXml.ToString)
Console.ReadLine()
End Sub
End Module
The following code snippet written in Visual C# .NET shows how to load an XML DOM using Load method:
using System;
using System.IO;
using System.Xml;
class Class1{
static void Main()
{
XmlDocument myDoc = new XmlDocument();
MyDoc.Load("students.xml");
Console.WriteLine(myDoc.InnerXml.ToString);
Console.ReadLine();
}
}
using System.IO;
using System.Xml;
class Class1{
static void Main()
{
XmlDocument myDoc = new XmlDocument();
MyDoc.Load("students.xml");
Console.WriteLine(myDoc.InnerXml.ToString);
Console.ReadLine();
}
}
The XmlReader class and the XmlWriter class derived from the System.Xml namespace are abstract base classes that parse and write XML data from streams or XML documents. In the following sub-headings these classes have been fully illustrated.
Options:
Printer Friendly
Email Friend
About The Author:
uCertify was formed in 1996 with an aim to offer high quality educational training software and services in the field of information technology to its customers. uCertify provides exam preparation solutions for the certification exams of Microsoft, CIW, CompTIA, Oracle, Sun and other leading IT vendors. To know more about uCertify, please visit http://www.ucertify.com/
uCertify was formed in 1996 with an aim to offer high quality educational training software and services in the field of information technology to its customers. uCertify provides exam preparation solutions for the certification exams of Microsoft, CIW, CompTIA, Oracle, Sun and other leading IT vendors. To know more about uCertify, please visit http://www.ucertify.com/
