ASP.NET and XML
1
Presented By:
Shravan S. Mylavarapu
Overview
2
Introduction to XML
ASP.NET Web Development
The Role of XML in ASP.NET
XML Integration in ASP.NET
Processing XML
XMLWriter and XMLReader
Xpath
XML Serialization
Introduction to XML
XML specification and XML
XML specification is a set of guidelines, defined by the World
Wide Web Consortium (W3C), for describing structured data in
plain text.
XML is a markup language (like HTML) based on tags within
angled brackets, and is also a subset of SGML (Standard
Generalized Markup Language).
3
The textual nature of XML makes the data highly portable and
broadly deployable. XML does not have a fixed set of tags. The
ability to create new tags makes XML a truly extensible
language.
ASP.NET Web Development
ASP.NET represents the next generation of web development
on the Windows platform.
ASP.NET includes many new features related to Web Forms,
such
as
deployment,
state
management,
caching,
configuration, debugging, data access as well as Web
Services.
We will focus on XML features of ASP.NET
4
The Role of XML in ASP.NET
5
.NET Framework makes use of XML
internally in many situations and thus it
allows XML to be easily used from our
applications.
XML pervades the entire Framework, and
ASP.NET’s XML integration can be used to
build highly extensible web sites and Web
Services.
XML Integration in ASP.NET
The System.Xml Namespace
–
–
–
–
Web Services
–
6
Create and process XML documents using
streaming API or DOM
Query XML documents
Transform XML documents
Validate XML documents
ASP.NET Web Services are programmable logic
that can be accessed from anywhere on the
Internet, using HTTP(GET/POST/SOAP) and XML
XML Integration in ASP.NET
(contd…)
SQLXML Managed Classes
–
The ADO.NET DataSet Class
–
7
Can be serialized as XML and conversely, populated
from XML
The .config Files
–
Allow access to SQL Server’s native and extended
XML features.
Web.config
C# Code Documentation
–
/// Used to document the source code with XML tags
Processing XML
Document Object Model
–
Simple API for XML (SAX)
–
8
Using DOM, the parser loads the entire XML
document into the memory at once as a tree,
providing random access to it for searching and
modifying any element in the document.
SAX follows a streaming model, reading an XML
document character by character as a stream and
generating events as each element or attribute is
encountered.
XmlWriter and XMLReader
9
using System.Xml;
<?xml version="1.0" ?>
<BankAccount>
<Number>1234</Number>
<Name>Raman Nair</Name>
<Type>Checking</Type>
<OpenDate>11/04/1974</OpenDate>
<Balance>25382.20</Balance>
</BankAccount>
XmlWriter
XmlTextWriter bankWriter = null;
bankWriter = new XmlTextWriter (m_strFileName, null);
bankWriter.Formatting = Formatting.Indented;
bankWriter.Indentation= 6;
bankWriter.Namespaces = false;
bankWriter.WriteStartDocument();
bankWriter.WriteStartElement("", "BankAccount", "");
bankWriter.WriteStartElement("", “Balance", "");
bankWriter.WriteString("1234");
bankWriter.WriteEndElement();
bankWriter.WriteStartElement("", "Name", "");
bankWriter.WriteString("Darshan Singh");
bankWriter.WriteEndElement();
10
bankWriter.WriteEndElement();
bankWriter.Flush();
XmlReader
XmlTextReader bankReader = null;
bankReader = new XmlTextReader (m_strFileName);
while (bankReader.Read())
{
if (bankReader.NodeType == XmlNodeType.Element)
{
if (bankReader.LocalName.Equals("Name"))
{
Console.Write("{0} has balance of $", bankReader.ReadString());
}
if (bankReader.LocalName.Equals("Balance"))
{
Console.WriteLine("{0}", bankReader.ReadString());
}
}
}
11
XPath
12
XPath is a standard language for retreiving
data in XML document.
System.Xml.XmlNode
System.Xml.XPath.XPathDocument
System.Xml.Xpath.XPathNavigator
Example: /BankAccount/Number
XML Serialization
13
Serialization is the process of converting an object into a
form that can be readily transported. For example, you can
serialize an object and transport it over the Internet using
HTTP between a client and a server. On the other end,
deserialization reconstructs the object from the stream.
XML serialization serializes only the public fields and
property values of an object into an XML stream. XML
serialization does not include type information. For example,
if you have a Book object that exists in the Library
namespace, there is no guarantee that it will be deserialized
into an object of the same type.
XML Serialization (contd…)
XMLSerializer class
–
http://msdn2.microsoft.com/enus/library/182eeyhh.aspx
Examples:
–
–
14
Serialize and Deserialize methods
http://msdn2.microsoft.com/enus/library/58a18dwa.aspx
http://www.devhood.com/Tutorials/tutorial_details.as
px?tutorial_id=236
References
15
Professional ASP.NET XML with C# - Wrox publications
.NET and XML – Niel M. Bornstein
http://www.perfectxml.com/articles/xml/msxml30.asp#int
ro
http://www.devhood.com/Tutorials/tutorial_details.aspx?
tutorial_id=236
http://www.perfectxml.com/articles/xml/msxml30.asp#int
ro
http://www.devhood.com/Tutorials/tutorial_details.aspx?
tutorial_id=236
Questions
16
Thank You
17
© Copyright 2026 Paperzz