<?xml version=’1.0’?>
<!-- This file is a part of a book store inventory database -->
<bookstore xmlns=”http://example.books.com”>
<book genre=”autobiography” publicationdate=”1981” ISBN=”1-861003-11-0”>
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
</bookstore>
XML Reader Class
XmlReader reader = XmlReader.Create(XMLFileName, XmlReaderSettings);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element
&& “book” == reader.Name)
{
Response.Write(reader.Name);
}
}
XML WriterClass
XmlWriterSettings settings = new
XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = true;
XmlWriter writer = XmlWriter.Create(Response.OutputStream, settings)
writer.WriteStartDocument();
writer.WriteStartElement("bookstore");
writer.WriteStartElement("book");
writer.WriteStartAttribute("publicationdate");
writer.WriteValue(publicationdate);
writer.WriteEndAttribute();
writer.WriteStartElement("price");
writer.WriteValue(price);
writer.WriteEndElement(); //end of price
writer.WriteEndElement(); //end of book
writer.WriteEndElement(); //end of bookstore
writer.WriteEndDocument();
XPathDocument Class
XPathDocument document = new XPathDocument(bookXMLFileName);
XPathNavigator nav = document.CreateNavigator();
XmlNamespaceManager namespaceMgr = new
XmlNamespaceManager(nav.NameTable);
namespaceMgr.AddNamespace("b", "http://tempuri.org/Book.xsd");
foreach( XPathNavigator node in
nav.Select("//b:book[not(b:price[. < 6.00])]/b:price",namespaceMgr))
{
Decimal price = (decimal)node.ValueAs(typeof(decimal));
Response.Write(String.Format("Search result: {0}<BR/>", price));
}