Overview of XML programming in Dot Net #24

Overview of XML programming in Dot Net

XML DOM(Document Object Model)

Three ways to read XML documents in dot net are: XML DOM, SAX, XMLReader.DOM loads entire XML data into memory for processing, it is both read-write, I mean you can change XML data and save. DOM uses data-structures to represent the data in the RAM.

SAX does not load all XML data in memory rather processes sequentially. SAX is good for just reading large XML file/data but as it does not store the data in the RAM and does not use any data structure, it can not perform complex operations(search) on the data.

XmlReader class of the .net framework can also be used to read and process xml data. It provides read only and forward only access.

How XML DOM works?

The root node of an XML document is represented by the XmlDocument. XmlDocument is derived from XmlNode class. XmlDocument provides methods such as Load(Load XML data from file), LoadXml(takes XML string as parameter to load), and Save(to save XML data into a file). Also, you can use XmlDocument to traverse through the XML data and process/print

Example code:Vb.net

dim xmlDo as New XmlDocument

xmlDoc.load(emp.xml);//or xmlDoc.loadXml(“”);

Console.WriteLine(xmlDoc.InnerXml.ToString)

xmlDoc.save(“newDoc.xml”);

C#

XmlDocument xmlDoc = New XmlDocument();

xmlDoc.load(emp.xml);//or xmlDoc.loadXml(“”);

Console.WriteLine(xmlDoc.InnerXml.ToString())

xmlDoc.save(“newDoc.xml”);

Parsing an XML document

————————

C#

count=0;

i=1;

XmlNode node=xmlDoc.ChildNodes[1];

foreach(XmlNode node1 in node.ChildNodes)

{

foreach(XmlNode node2 in node1.ChildNodes)

{

Console.WriteLine(xmlDoc.DocumentElement.FirstChild.ChildNodes[count].Name+”:”+node2.FirstChild.Value); count = count + 1;

}

i=i+1;

count=0;

}

count =0

i=1

dim node1 as XmlNode;

node1 = xmlDoc.ChildNodes(1)

foreach node1 in node1.ChildNodes

dim node2 as XmlNode

foreach node2 in node1.ChildNodes

xmlDoc.DocumentElement.FirstChild.ChildNodes(count).Name +”:”+node2.FirstChild.value

next

i=1+1

count=0

next

———- From: http://sitestree.com/?p=4747
Categories:24
Tags:
Post Data:2011-04-21 04:17:46

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>