Reading and writing with XML in visual programming.pptx
azkamurat
19 views
7 slides
Sep 12, 2024
Slide 1 of 7
1
2
3
4
5
6
7
About This Presentation
Reading and writing in XML in c#
Size: 49.04 KB
Language: en
Added: Sep 12, 2024
Slides: 7 pages
Slide Content
Reading and writing with XML Visual programming
. NET provides five namespace System.Xml System.Xml.Schema System.Xml.Serialization System.Xml.Xpath System.Xml.Xsl to support XML classes.
The System.Xml namespace contains major XML classes. This namespace contains many classes to read and write XML documents . These reader and writer classes are used to read and write XML documents. These classes are:
The XmlReader class is an abstract bases class and contains methods and properties to read a document . Some of these methods are MoveToAttribute , MoveToFirstAttribute , MoveToContent , MoveToFirstContent , MoveToElement and MoveToNextAttribute . ReadString , ReadInnerXml , ReadOuterXml , and ReadStartElement are more read methods
How to read XML Documents? XmlTextReader textReader = new XmlTextReader ("C:\\books.xml");
Code example using System; using System.Xml ; namespace ReadXml1 { class Class1 { static void Main(string[] args ) { // Create an isntance of XmlTextReader and call Read method to read the file XmlTextReader textReader = new XmlTextReader ("C:\\books.xml"); textReader.Read (); // If the node has value while ( textReader.Read ()) { // Move to fist element textReader.MoveToElement (); Console.WriteLine (" XmlTextReader Properties Test"); Console.WriteLine ("==================="); // Read this element's properties and display them on console Console.WriteLine ("Name:" + textReader.Name ); Console.WriteLine ("Base URI:" + textReader.BaseURI ); Console.WriteLine ("Local Name:" + textReader.LocalName ); Console.WriteLine ("Attribute Count:" + textReader.AttributeCount.ToString ()); Console.WriteLine ("Depth:" + textReader.Depth.ToString ()); Console.WriteLine ("Line Number:" + textReader.LineNumber.ToString ()); Console.WriteLine ("Node Type:" + textReader.NodeType.ToString ()); Console.WriteLine ("Attribute Count:" + textReader.Value.ToString ()); } } } }