aspnet7
aspnet7
SURENDRANAGAR
CLASS:- BCA/BSCIT SEMESTER -5
SUBJECT:- Asp.net
Prepared By:- Bhartiba parmar
Chapter-4
Using Xml
• Contents
What is xml?
Reading datasets from xml
Writing dataset with xml
What is webservice?
Creating a webservice.
What is xml
• Xml (eXtensible Markup Language) is a mark up language.
• XML is designed to store and transport data.
• Xml was released in late 90’s. it was created to provide an easy to use and store
self describing data.
• XML became a W3C Recommendation on February 10, 1998.
• XML is not a replacement for HTML.
• XML is designed to be self-descriptive.
• XML is designed to carry data, not to display data.
• XML tags are not predefined. You must define your own tags.
• XML is platform independent and language independent.
There are basic rules for building XML:
All XML must have a root element.
All tags must be closed.
All tags must be properly nested.
Tag names have strict limits.
Tag names are case sensitive.
Tag names cannot contain spaces.
Attribute values must appear within quotes ("").
White space is preserved.
HTML tags should be avoided (optional).
Write XML Data
Writing Dataset or DataTable as XML is done by using two methods.
1)WriteXml() Method
2)WriteXmlSchema() Method
1)WriteXml() method
• This method is used to read data from Dataset and write data as XML data.
• While writing dataset you should consider following things.
• All tables of datasets are treated as Main Elements.
• All rows of tables are treated as sub elements.
• All columns of tables are treated as data elements which has actual data of table.
• There is only one Root Element in xml file.
2)WriteXmlSchema() Method
• XmlSchema is a file which contains rules for Xml Element and their data.If you use only WriteXml()
method,only data is written as Xml.But if you want to write schema information,you can use
WriteXmlSchema() method.
Examle
}
Read Xml Data
• There are two methods for reading datasets with XML.
1)ReadXml() Method
2)ReadXmlSchema() method
1)ReadXml() Method
• This method is used to read Xml data from any Xml file to dataset or datatable.
• While reading dataset or datatable it does as follows
• It treats all main elements under root element as different tables,if you are using DataSet to read
the data.
• It automatically stores data in xml way,because you are already reading a file which is in xml
format.
2) ReadXmlSchema() method
• If you use only ReadXml() method.It just reads entire data from Xml and stores it into DataSet or
DataTable.But before reading Xml data into DataSet,if you want to specify some schema
rules(data rules) before writing xml data to DataSet/DataTable,you can use ReadXmlSchema()
which allows you to specify XSD file and it restrics the data being copied into DataSet/DataTable.
Example
protected void btn_ReadXml_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(MapPath("StudXml.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
}
What is WebService?
Go to Visual Studio then click on "File" -> "Website" -> "ASP.NET empty website template".