Previous | Home | Next |
.NET Framework has extensive support for working with XML Language. In the .NET framework, the support for XML documents includes
- XML namespace
- XML designer
- XML Web Server control
- XML DOM support
XML Namespace
The System.Xml namespace provides a Large set of classes for processing XML data.There Are more classes such as
XmlTextReader- It Provides forward only access to a stream of XML data and checks whether or not an XML document is well formed. This class neither creates as in-memory structure nor validates the XML document against the DTD. You can declare an object of the XmlTextReader class by including the System.Xml namespace in the application. The syntax to declare an object of this class is as follows
XmlTextReader reader = new XmlTextReader("XML1.xml");It is important to note that the .xml file you pass as an argument to the constructor of the XmlTextReader class exists in the \WINNT\System32 folder
XmlTextWriter- Provides forward only way of generating streams or files containing XML data that conforms to W3C XML 1.0. If you want to declare an object of the XmlTextWriter class, you must include the System.Xml. The syntax to decare an object of this class is as follows
XmlTextWriter writer = new XmlTextWriter(Response.Output);Here Response.Output represents an outgoing HTTP response stream to which you want to send the XML data.
XmlDataDocument- Provides support for XML and relational data in W3C XML DOM. You can use this class with a dataset to provide relational and non-relational views of the same set of data. This class is primarily used when you want to access the functions of ADO.NET. The syntax to declare an object of this class is as follows
DataSet ds=new DataSet(); XmlDataDocument doc=new XmlDocument(ds);
There are a number of reasons to use XmlDataDocument
- It gives you the freedom to work with any data by using the DOM.
- There is synchronization between an XmlDatadocument and a DataSet, and any changes in one will be reflected in the other.
- When an XML document is loaded into an XmlDatadocument, the schema is preserved.
How to Create XML Application in .Net
Visual Studio .NET provides the XML designer that you can use to create and edit XML documents. you need to perform the following steps by using the XML designer of Visual Studio .NET
- Create a new ASP.NET Web application.
- Select the Add New Item option and Choose Xml File

- Select XML File as the template from the right pane. Specify the name as "Registraion.xml" and click open.
- The XML designer is displayed. The XML designer has automatically generated a line that notifies the browser that the document being processed is an XML document, as displayed in the figure

How to Display Xml File In Gridview
.cs Code
DataSet ds = new DataSet(); ds.ReadXml(MapPath("Registration.xml")); GridView1.DataSource = ds; GridView1.DataBind();
Code of Registration.xml file
<?xml version="1.0" encoding="utf-8" ?> <registration> <userdata> <firstname>santhu</firstname> <mobileno>98480</mobileno> <country>India</country> <emailId>santhweb@gmail.com</emailId> <loginname>santhu</loginname> <loginPwd>web123</loginPwd> </userdata> <userdata> <firstname>raju</firstname> <mobileno>9838610261</mobileno> <country>India</country> <emailId>rajuweb@gmail.com</emailId> <loginname>raju</loginname> <loginPwd>raju123</loginPwd> </userdata> <userdata> <firstname>kiran</firstname> <mobileno>9998888785</mobileno> <country>India</country> <emailId>kiranweb@gmail.com</emailId> <loginname>kiran</loginname> <loginPwd>kiran222</loginPwd> </userdata> <userdata> <firstname>rakesh</firstname> <mobileno>9990512118</mobileno> <country>India</country> <emailId>Ankit@gmail.com</emailId> <loginname>rakesh </loginname> <loginPwd>rak345</loginPwd> </userdata> <userdata> <firstname>john</firstname> <mobileno>9838610261</mobileno> <country>India</country> <emailId>john@gmail.com</emailId> <loginname>john</loginname> <loginPwd>john234</loginPwd> </userdata> </registration>
Output

Previous | Home | Next |