XML support in .net framework
XML Namespace:The .net framework give support for xml documents.The namespace system.xml support various classes that are used to deal with XML language.
The commonly used classes for xml data are,
1)XmlTextReader:The instance created by using this class provide forward only access to xml data.It checks whether XML data is well formed.The syntax to declare object of this class,
XmlTextReader mWriter=new XmTextReader("tmpXML.xml");
2)XmlTextWriter:Provides forward only way of generating streams or files containing XML data that conforms to w3c xml standered.The syntax to declare object of this class,
XmlTextWriter mReader=new XmlTextWriter("tmpXML.xml");
3)XmlDocument:This class allows navigation and editing of XML nodes.This class also support XML DOM.The syntax to declare object of this class,
XmlDocument mDoc=new XmlDocument();
4)XmlDataDocument:One can use this class with dataset to providerelational and non-relational views of the same set of data.This class is normally used to access functionality of ado.net.This class support XML DOM.The syntax to declare object of this class,
Dataset ds1 =new dataset();
XmlDataDocument mDoc=new XmlDataDocument(ds1);
5)XmlNodeReader:This class provide forward only access to the data represented by XmlDocument and XmlDataDocument class.This class support XML DOM.The syntax to declare object of this class,
XmlDocument mDoc=new XmlDocument();
XmlNodeReader mNode=new XmlNodeReader(mDoc);
6)XslTransform:This class provide support for XSLT documents.You need to include system.xsl namespace before using this class.The syntax to declare object of this class,
XslTransform mDoc=new XslTransform();
XML Web Server Control:
The .net framework provide XML web server control.This control is used to display contents of an XML documents without formatting or using XSL transformation.
The XML web server control has the following properties,
DocumentSource:Allows you to specify the Uniform Resource Locater or the path pf the XML Documents.
TransformSource:Allows you to specify the Uniform Resource Locater(URL) of XSLT file or the path pf the XML Documents.
Document:Instance of XmlDocumet class.
Transfomrm:Instance of XslTransform class.
Load XML document into dataset:
The dataset object has ReadXml methode which is used to read data into the dataset from an XML file.
The syntax to declare ReadXml method,
ReadXml(Stream|File|textReader|XMLReader,XmlReadMode);
The ReadXml method can read data from Stream|File|textReader|XMLReader
XMLReadMode can take following values,
Auto
DiffGram
Fragment
IgnoreSchema
InferSchema
ReadSchema
If you want to represent XML(Menu.xml) document with a dataset:
One can read Menu.xml file int o dataset and bind the datagrid control by adding following code at load event.
public sub load()
{
dataset ds=new dataset();
ds.ReadXml(MapPath("Menu.xml"));
datagrid1.datasource=ds;
datagrid1.databind();
}
