本次课程内容包括
? LINQ to XML 简介 ? LINQ to XML 类 ? 使用 LINQ to XML ? 实现:生成 RSS
议程
? LINQ to XML 简介 ? LINQ to XML 类 ? 使用 LINQ to XML ? 实现:生成 RSS
使用 LINQ 访问 XML
? 更好的操作 XML ? 支持语言集成查询
? 更方便、更快速、更简单、更智能的 XML
API
LINQ to XML
? LINQ to XML 是一种启用了 LINQ 的内存
XML编程接口,使用它,可以在.NET Framework 编程语言中处理 XML。
? 它将 XML 文档置于内存中 ,这一点很像文
档对象模型 (DOM)。
? 它提供一种新的对象模型,这是一种更轻
量的模型,使用也更方便,这种模型利用 了 Visual C# 2008 在语言方面的改进。
议程
? LINQ to XML 简介 ? LINQ to XML 类 ? 使用 LINQ to XML ? 实现:生成 RSS
XElement 类
? 它表示一个 XML 元素 ? 可以使用该类
- 创建元素
- 更改元素内容
- 添加、更改或删除子元素 - 向元素中添加属性
- 以文本格式序列化元素内容
? 可以与 System.Xml 中的其他类(例如
XmlReader、XmlWriter 和
XslCompiledTransform)进行互操作
XAttribute 类
? 属性是与元素关联的名称/值对 ?XAttribute 类表示 XML 属性
? 属性集合的 LINQ 查询表达式与元素集合的
LINQ查询表达式看起来非常相似
XDocument 类
? XDocument 类包含有效的 XML 文档所需的信息。
其中包括 XML 声明、处理指令和注释。 ? 如果需要 XDocument 类提供的特定功能,您只
需创建 XDocument 对象。在很多情况下,可以 直接使用 Xelement。直接使用 XElement 是一种 比较简单的编程模型。
? XDocument 是从 XContainer 派生的。 因此,它
可以包含子节点。但是,XDocument 对象只能有 一个子 XElement 节点。 这反映了 XML 标准, 即在 XML 文档中只能有一个根元素。
议程
? LINQ to XML 简介 ? LINQ to XML 类 ? 使用 LINQ to XML ? 实现:生成 RSS
XElement 类功能
? 构造 XML 树
? 序列化 XML 树
? 通过轴方法检索 XML 数据 ? 查询 XML 树
? 修改 XML 树
构造 XML 树
? “函数构造”方法
- 通过将查询结果用作 XElement 和 XAttribute
对象构造函数的参数,实现了一种功能强大的 创建 XML 树的方法。
- 利用这种方法,开发人员可以方便地将 XML
树从一种形状转换为另一种形状。
? 分析字符串
? 从文件加载
序列化 XML 树
? XML 树可以序列化为
- 字符串
- File
TextWriter- XmlWriter - XmlReader
LINQ to XML 轴
? XNode::Ancestors
? XContainer::Descendants ? XNode::ElementsAfterSelf
library
XNode::ElementsBeforeSelf?
ancestor
? XElement::AncestorsAndSelf
After
book[2]
? XElement::DescendantsAndSelf book[1]
Before
self
chapter[1]
chapter[2]
chapter[3]
section[1]
descendant
paragraph[1]
paragraph[2]
查询与转换 XML 树
? 基本查询
? 使用LINQ查询操作符查询 ? 转换 XML 格式
? 将集合、数据转换成 XML ? 转换成其它数据格式
修改 XML 树
? 内存中 XML 树修改与函数构造 ? 向 XML 树中添加元素、属性和节点 ? 修改 XML 树中的元素、属性和节点 ? 从 XML 树中移除元素、属性和节点 ? 维护名称/值对
? 更改整个 XML 树的命名空间
回顾
? LINQ to XML 简介 ? LINQ to XML 类 ? 使用 LINQ to XML ? 实现:生成 RSS
实例:生成 RSS
NorthwindDataContext db = newNorthwindDataContext();
XElement rssRoot = newXElement("rss",
new XAttribute("version","2.0"), new XElement(“channel”,
new XElement("title", "MyRSS Feed"), new XElement("link", "http://weblogs.asp.net"),new XElement("description" , "Northwind Products Feed"),from product in db.Products
orderby product.ProductName descendingselect new XElement("item",
new XElement("title",product.ProductName), new XElement("link","p.aspx?id="+product.ProductID), newXElement("description", "Supplier: " +
product.Supplier.CompanyName)
)
)
);
Response.Write(rssRoot.ToString());
回顾
? LINQ to XML 简介 ? LINQ to XML 类 ? 使用 LINQ to XML ? 实现:生成 RSS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.Xml.Xsl;
namespace LINQtoXML
{
class Program
{
static void Main(string[] args)
{
//构造 XML 树
//BuildXmlTreeUsingDom();
//BuildXmlTree();
//BuildXmlTreeWithLINQ();
//BuildXmlTreeWithAttributes();
//BuildXmlDocument();
//ParseXml();
//LoadXmlFromFile();
//CatchException();
//CreateXElementUsingXmlReader();
//序列化 XML 树
//SerializeToFile1();
//SerializeToFile2();
//SerializeToXmlReader();
//查询 XML
//QueryElements();
//QueryElements2();
//QueryAttributes();
//使用 LINQ 查询操作符进行查询
//LINQQuery1();
//LINQQuery2();
//LINQQuery3();
//LINQQuery4();
//LINQQuery5();
//转换
//XmlTransform1();
//XmlTransform2();
//XmlTransform3();
//修改 XML 树
//ModifyXml1();
//ModifyXml2();
//ModifyXml3();
//ModifyXml4();
}
private static void SerializeToXmlReader()
{
string xslMarkup = @"<?xml version='1.0'?>
<xsl:stylesheetxmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:templatematch='/Parent'>
<Root>
<C1>
<xsl:value-ofselect='Child1'/>
</C1>
<C2>
<xsl:value-ofselect='Child2'/>
</C2>
</Root>
</xsl:template>
</xsl:stylesheet>";
XDocument xmlTree = new XDocument(
newXElement("Parent",
newXElement("Child1", "Child1 data"),
newXElement("Child2", "Child2 data")
)
);
XDocument newTree = new XDocument();
using (XmlWriter writer =newTree.CreateWriter())
{
// Load the style sheet.
XslCompiledTransform xslt = newXslCompiledTransform();
xslt.Load(XmlReader.Create(newStringReader(xslMarkup)));
// Execute the transformationand output the results to a writer.
xslt.Transform(xmlTree.CreateReader(), writer);
}
Console.WriteLine(newTree);
}
private static void SerializeToFile2()
{
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
using (XmlWriter xw = XmlWriter.Create(sb, xws))
{
XElement root = newXElement("Root",
newXElement("Child", "child content")
);
root.Save(xw);
}
Console.WriteLine(sb.ToString());
}
private static void SerializeToFile1()
{
XElement root = new XElement("Root",
new XElement("Child","child content")
);
root.Save("Root.xml");
string str = File.ReadAllText("Root.xml");
Console.WriteLine(str);
}
private static void ModifyXml4()
{
// Create an element with no content.
XElement root = new XElement("Root");
// Add a number of name/value pairs as attributes.
root.SetAttributeValue("Top", 22);
root.SetAttributeValue("Left", 20);
root.SetAttributeValue("Bottom", 122);
root.SetAttributeValue("Right", 300);
root.SetAttributeValue("DefaultColor", "Color.Red");
Console.WriteLine(root);
// Replace the value of Top.
root.SetAttributeValue("Top", 10);
Console.WriteLine(root);
// Remove DefaultColor.
root.SetAttributeValue("DefaultColor", null);
Console.WriteLine(root);
}
private static void ModifyXml3()
{
XElement root = XElement.Parse(@"<Root>
<Child1>
<GrandChild1/>
<GrandChild2/>
<GrandChild3/>
</Child1>
<Child2>
<GrandChild4/>
<GrandChild5/>
<GrandChild6/>
</Child2>
<Child3>
<GrandChild7/>
<GrandChild8/>
<GrandChild9/>
</Child3>
</Root>");
root.Element("Child1").Element("GrandChild1").Remove();
root.Element("Child2").Elements().ToList().Remove();
root.Element("Child3").Elements().Remove();
Console.WriteLine(root);
}
private static void ModifyXml2()
{
XElement srcTree = new XElement("Root",
newXElement("Element1", 1),
new XElement("Element2",2),
newXElement("Element3", 3),
newXElement("Element4", 4),
newXElement("Element5", 5)
);
XElement xmlTree = new XElement("Root",
newXElement("Child1", 1),
newXElement("Child2", 2),
newXElement("Child3", 3),
newXElement("Child4", 4),
newXElement("Child5", 5)
);
xmlTree.Add(new XElement("NewChild", "newcontent"));
xmlTree.Add(
from el in srcTree.Elements()
where (int)el > 3
select el
);
// Even though Child9 does not exist in srcTree, the following statementwill not
// throw an exception, and nothing will be added to xmlTree.
xmlTree.Add(srcTree.Element("Child9"));
Console.WriteLine(xmlTree);
}
private static void ModifyXml1()
{
XElement root = XElement.Parse("<?xml version=\"1.0\"encoding=\"utf-8\" ?><Root Data1=\"123\"Data2=\"456\"><Child1>Content</Child1></Root>");
foreach (XAttribute att in root.Attributes())
{
root.Add(new XElement(att.Name,(string)att));
}
root.Attributes().Remove();
Console.WriteLine(root);
}
private static void XmlTransform3()
{
XElement custOrd = XElement.Load("CustomersOrders.xml");
IEnumerable<Customer> custList =
from el incustOrd.Element("Customers").Elements("Customer")
select new Customer(
(string)el.Attribute("CustomerID"),
(string)el.Element("CompanyName"),
(string)el.Element("ContactName")
);
foreach (Customer cust in custList)
Console.WriteLine(cust);
}
private static void XmlTransform2()
{
XElement co = XElement.Load("CustomersOrders.xml");
XElement newCustOrd =
new XElement("Root",
from cust inco.Element("Customers").Elements("Customer")
select newXElement("Customer",
cust.Attributes(),
cust.Elements(),
newXElement("Orders",
from ord inco.Element("Orders").Elements("Order")
where(string)ord.Element("CustomerID") ==(string)cust.Attribute("CustomerID")
select newXElement("Order",
ord.Attributes(),
ord.Element("EmployeeID"),
ord.Element("OrderDate"),
ord.Element("RequiredDate"),
ord.Element("ShipInfo")
)
)
)
);
Console.WriteLine(newCustOrd);
}
private static void XmlTransform1()
{
Dictionary<string, string> dict = new Dictionary<string,string>();
dict.Add("Child1", "Value1");
dict.Add("Child2", "Value2");
dict.Add("Child3", "Value3");
dict.Add("Child4", "Value4");
XElement root = new XElement("Root",
from keyValue in dict
select newXElement(keyValue.Key, keyValue.Value)
);
Console.WriteLine(root);
}
private static void LINQQuery5()
{
XElement root = XElement.Load("Data.xml");
IEnumerable<decimal> extensions =
from el inroot.Elements("Data")
let extension =(decimal)el.Element("Quantity") *(decimal)el.Element("Price")
where extension >= 25
orderby extension
select extension;
foreach (decimal ex in extensions)
Console.WriteLine(ex);
}
private static void LINQQuery4()
{
XElement root = XElement.Load("Data.xml");
IEnumerable<decimal> prices =
from el inroot.Elements("Data")
let price = (decimal)el.Element("Price")
orderby price
select price;
foreach (decimal el in prices)
Console.WriteLine(el);
}
private static void LINQQuery3()
{
XElement root = XElement.Parse(@"<Root>
<Child1>
<GrandChild1>GC1Value</GrandChild1>
</Child1>
<Child2>
<GrandChild2>GC2Value</GrandChild2>
</Child2>
<Child3>
<GrandChild3>GC3Value</GrandChild3>
</Child3>
<Child4>
<GrandChild4>GC4Value</GrandChild4>
</Child4>
</Root>");
string grandChild3 = (string)
(from el inroot.Descendants("GrandChild3")
select el).First();
Console.WriteLine(grandChild3);
}
private static void LINQQuery2()
{
XElement root = XElement.Parse(@"<root>
<para>
<r>
<t>Some text </t>
</r>
<n>
<r>
<t>that is broken upinto </t>
</r>
</n>
<n>
<r>
<t>multiplesegments.</t>
</r>
</n>
</para>
</root>");
IEnumerable<string> textSegs =
from seg inroot.Descendants("t")
select (string)seg;
string str = textSegs.Aggregate(new StringBuilder(),
(sb, i) => sb.Append(i),
sp => sp.ToString()
);
Console.WriteLine(str);
}
private static void LINQQuery1()
{
XElement root = XElement.Load("PurchaseOrder.xml");
IEnumerable<XElement> address =
from el inroot.Elements("Address")
where(string)el.Attribute("Type") == "Billing"
select el;
foreach (XElement el in address)
Console.WriteLine(el);
}
private static void QueryAttributes()
{
XElement val = new XElement("Value",
new XAttribute("ID","1243"),
newXAttribute("Type", "int"),
newXAttribute("ConvertableTo", "double"),
"100");
IEnumerable<XAttribute> listOfAttributes =
from att in val.Attributes()
select att;
foreach (XAttribute a inlistOfAttributes)
Console.WriteLine(a);
}
private static void QueryElements2()
{
XElement purchaseOrders = XElement.Load("PurchaseOrders.xml");
IEnumerable<XElement> names =
from el in purchaseOrders
.Elements("PurchaseOrder")
.Elements("Address")
.Elements("Name")
select el;
foreach (XElement e in names)
Console.WriteLine(e);
}
private static void QueryElements()
{
XElement po = XElement.Load("PurchaseOrder.xml");
IEnumerable<XElement> childElements =
from el in po.Elements()
select el;
foreach (XElement el in childElements)
Console.WriteLine("Name:" + el.Name);
}
private static void CreateXElementUsingXmlReader()
{
XmlReader r = XmlReader.Create("books.xml");
while (r.NodeType != XmlNodeType.Element)
r.Read();
XElement e = XElement.Load(r);
Console.WriteLine(e);
}
private static void CatchException()
{
try
{
XElement contacts =XElement.Parse(
@"<Contacts>
<Contact>
<Name>JimWilson</Name>
</Contact>
</Contcts>");
Console.WriteLine(contacts);
}
catch (System.Xml.XmlException e)
{
Console.WriteLine(e.Message);
}
}
private static void LoadXmlFromFile()
{
XElement booksFromFile = XElement.Load(@"books.xml");
Console.WriteLine(booksFromFile);
}
private static void ParseXml()
{
XElement contacts = XElement.Parse(
@"<Contacts>
<Contact>
<Name>PatrickHines</Name>
<PhoneType=""home"">206-555-0144</Phone>
<Phonetype=""work"">425-555-0145</Phone>
<Address>
<Street1>123 MainSt</Street1>
<City>Mercer Island</City>
<State>WA</State>
<Postal>68042</Postal>
</Address>
<NetWorth>10</NetWorth>
</Contact>
<Contact>
<Name>GretchenRivas</Name>
<PhoneType=""mobile"">206-555-0163</Phone>
<Address>
<Street1>123 MainSt</Street1>
<City>Mercer Island</City>
<State>WA</State>
<Postal>68042</Postal>
</Address>
<NetWorth>11</NetWorth>
</Contact>
</Contacts>");
Console.WriteLine(contacts);
}
private static void BuildXmlDocument()
{
XDocument d = new XDocument(
new XComment("This is acomment."),
newXProcessingInstruction("xml-stylesheet",
"href='mystyle.css'title='Compact' type='text/css'"),
new XElement("Pubs",
newXElement("Book",
newXElement("Title", "Artifacts of Roman Civilization"),
newXElement("Author", "Moreno,Jordao")
),
newXElement("Book",
newXElement("Title", "Midieval Tools and Implements"),
newXElement("Author", "Gazit, Inbar")
)
),
new XComment("This isanother comment.")
);
d.Declaration = new XDeclaration("1.0", "utf-8","true");
Console.WriteLine(d);
d.Save("test.xml");
}
private static void BuildXmlTreeWithAttributes()
{
XElement c = new XElement("Customers",
newXElement("Customer",
newXElement("Name", "John Doe"),
newXElement("PhoneNumbers",
newXElement("Phone",
newXAttribute("type", "home"),
"555-555-5555"),
newXElement("Phone",
newXAttribute("type", "work"),
"666-666-6666")
)
)
);
Console.WriteLine(c);
}
private static void BuildXmlTreeWithLINQ()
{
XElement srcTree = new XElement("Root",
newXElement("Element", 1),
newXElement("Element", 2),
newXElement("Element", 3),
newXElement("Element", 4),
newXElement("Element", 5)
);
XElement xmlTree = new XElement("Root",
new XElement("Child",1),
new XElement("Child",2),
from el in srcTree.Elements()
where (int)el > 2
select el
);
Console.WriteLine(xmlTree);
}
private static void BuildXmlTree()
{
XElement contacts =
newXElement("Contacts",
newXElement("Contact",
newXElement("Name", "Patrick Hines"),
newXElement("Phone", "206-555-0144"),
newXElement("Address",
newXElement("Street1", "123 Main St"),
newXElement("City", "Mercer Island"),
newXElement("State", "WA"),
newXElement("Postal", "68042")
)
)
);
Console.WriteLine(contacts);
}
private static void BuildXmlTreeUsingDom()
{
XmlDocument doc = new XmlDocument();
XmlElement name = doc.CreateElement("Name");
name.InnerText = "Patrick Hines";
XmlElement phone1 = doc.CreateElement("Phone");
phone1.SetAttribute("Type", "Home");
phone1.InnerText ="206-555-0144";
XmlElement phone2 = doc.CreateElement("Phone");
phone2.SetAttribute("Type", "Work");
phone2.InnerText = "425-555-0145";
XmlElement street1 = doc.CreateElement("Street1");
street1.InnerText = "123 Main St";
XmlElement city = doc.CreateElement("City");
city.InnerText = "Mercer Island";
XmlElement state = doc.CreateElement("State");
state.InnerText = "WA";
XmlElement postal =doc.CreateElement("Postal");
postal.InnerText = "68042";
XmlElement address = doc.CreateElement("Address");
address.AppendChild(street1);
address.AppendChild(city);
address.AppendChild(state);
address.AppendChild(postal);
XmlElement contact = doc.CreateElement("Contact");
contact.AppendChild(name);
contact.AppendChild(phone1);
contact.AppendChild(phone2);
contact.AppendChild(address);
XmlElement contacts = doc.CreateElement("Contacts");
contacts.AppendChild(contact);
doc.AppendChild(contacts);
Console.WriteLine(doc.OuterXml);
}
}
}
Book.xml
<?xml version="1.0"?>
<Catalog>
<Book id="bk101">
<Author>Garghentini, Davide</Author>
<Title>XML Developer's Guide</Title>
<Genre>Computer</Genre>
<Price>44.95</Price>
<PublishDate>2000-10-01</PublishDate>
<Description>An in-depth look at creating applications
with XML.</Description>
</Book>
<Book id="bk102">
<Author>Garcia, Debra</Author>
<Title>Midnight Rain</Title>
<Genre>Fantasy</Genre>
<Price>5.95</Price>
<PublishDate>2000-12-16</PublishDate>
<Description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</Description>
</Book>
</Catalog>
CustomersOrders.xml
<?xml version="1.0"encoding="utf-8"?>
<Root>
<Customers>
<Customer CustomerID="GREAL">
<CompanyName>Great Lakes FoodMarket</CompanyName>
<ContactName>Howard Snyder</ContactName>
<ContactTitle>Marketing Manager</ContactTitle>
<Phone>(503) 555-7555</Phone>
<FullAddress>
<Address>2732 Baker Blvd.</Address>
<City>Eugene</City>
<Region>OR</Region>
<PostalCode>97403</PostalCode>
<Country>USA</Country>
</FullAddress>
</Customer>
<Customer CustomerID="HUNGC">
<CompanyName>Hungry Coyote Import Store</CompanyName>
<ContactName>Yoshi Latimer</ContactName>
<ContactTitle>Sales Representative</ContactTitle>
<Phone>(503) 555-6874</Phone>
<Fax>(503) 555-2376</Fax>
<FullAddress>
<Address>City Center Plaza516 Main St.</Address>
<City>Elgin</City>
<Region>OR</Region>
<PostalCode>97827</PostalCode>
<Country>USA</Country>
</FullAddress>
</Customer>
<Customer CustomerID="LAZYK">
<CompanyName>Lazy K KountryStore</CompanyName>
<ContactName>John Steel</ContactName>
<ContactTitle>Marketing Manager</ContactTitle>
<Phone>(509) 555-7969</Phone>
<Fax>(509) 555-6221</Fax>
<FullAddress>
<Address>12 Orchestra Terrace</Address>
<City>Walla Walla</City>
<Region>WA</Region>
<PostalCode>99362</PostalCode>
<Country>USA</Country>
</FullAddress>
</Customer>
<Customer CustomerID="LETSS">
<CompanyName>Let's Stop N Shop</CompanyName>
<ContactName>Jaime Yorres</ContactName>
<ContactTitle>Owner</ContactTitle>
<Phone>(415) 555-5938</Phone>
<FullAddress>
<Address>87 Polk St. Suite 5</Address>
<City>San Francisco</City>
<Region>CA</Region>
<PostalCode>94117</PostalCode>
<Country>USA</Country>
</FullAddress>
</Customer>
</Customers>
<Orders>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>6</EmployeeID>
<OrderDate>1997-05-06T00:00:00</OrderDate>
<RequiredDate>1997-05-20T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-05-09T00:00:00">
<ShipVia>2</ShipVia>
<Freight>3.35</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>8</EmployeeID>
<OrderDate>1997-07-04T00:00:00</OrderDate>
<RequiredDate>1997-08-01T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-07-14T00:00:00">
<ShipVia>2</ShipVia>
<Freight>4.42</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>1</EmployeeID>
<OrderDate>1997-07-31T00:00:00</OrderDate>
<RequiredDate>1997-08-28T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-08-05T00:00:00">
<ShipVia>2</ShipVia>
<Freight>116.53</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>4</EmployeeID>
<OrderDate>1997-07-31T00:00:00</OrderDate>
<RequiredDate>1997-08-28T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-08-04T00:00:00">
<ShipVia>2</ShipVia>
<Freight>18.53</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>6</EmployeeID>
<OrderDate>1997-09-04T00:00:00</OrderDate>
<RequiredDate>1997-10-02T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-09-10T00:00:00">
<ShipVia>1</ShipVia>
<Freight>57.15</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>3</EmployeeID>
<OrderDate>1997-09-25T00:00:00</OrderDate>
<RequiredDate>1997-10-23T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-09-30T00:00:00">
<ShipVia>3</ShipVia>
<Freight>76.13</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>4</EmployeeID>
<OrderDate>1998-01-06T00:00:00</OrderDate>
<RequiredDate>1998-02-03T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1998-02-04T00:00:00">
<ShipVia>2</ShipVia>
<Freight>719.78</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>3</EmployeeID>
<OrderDate>1998-03-09T00:00:00</OrderDate>
<RequiredDate>1998-04-06T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1998-03-18T00:00:00">
<ShipVia>2</ShipVia>
<Freight>33.68</Freight>
<ShipName>Great Lakes Food Market</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>3</EmployeeID>
<OrderDate>1998-04-07T00:00:00</OrderDate>
<RequiredDate>1998-05-05T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1998-04-15T00:00:00">
<ShipVia>2</ShipVia>
<Freight>25.19</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>4</EmployeeID>
<OrderDate>1998-04-22T00:00:00</OrderDate>
<RequiredDate>1998-05-20T00:00:00</RequiredDate>
<ShipInfo>
<ShipVia>3</ShipVia>
<Freight>18.84</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>GREAL</CustomerID>
<EmployeeID>4</EmployeeID>
<OrderDate>1998-04-30T00:00:00</OrderDate>
<RequiredDate>1998-06-11T00:00:00</RequiredDate>
<ShipInfo>
<ShipVia>3</ShipVia>
<Freight>14.01</Freight>
<ShipName>Great Lakes FoodMarket</ShipName>
<ShipAddress>2732 Baker Blvd.</ShipAddress>
<ShipCity>Eugene</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97403</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>HUNGC</CustomerID>
<EmployeeID>3</EmployeeID>
<OrderDate>1996-12-06T00:00:00</OrderDate>
<RequiredDate>1997-01-03T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1996-12-09T00:00:00">
<ShipVia>2</ShipVia>
<Freight>20.12</Freight>
<ShipName>Hungry Coyote ImportStore</ShipName>
<ShipAddress>City Center Plaza516 Main St.</ShipAddress>
<ShipCity>Elgin</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97827</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>HUNGC</CustomerID>
<EmployeeID>1</EmployeeID>
<OrderDate>1996-12-25T00:00:00</OrderDate>
<RequiredDate>1997-01-22T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-01-03T00:00:00">
<ShipVia>3</ShipVia>
<Freight>30.34</Freight>
<ShipName>Hungry Coyote Import Store</ShipName>
<ShipAddress>City Center Plaza516 Main St.</ShipAddress>
<ShipCity>Elgin</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97827</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>HUNGC</CustomerID>
<EmployeeID>3</EmployeeID>
<OrderDate>1997-01-15T00:00:00</OrderDate>
<RequiredDate>1997-02-12T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-01-24T00:00:00">
<ShipVia>1</ShipVia>
<Freight>0.2</Freight>
<ShipName>Hungry Coyote Import Store</ShipName>
<ShipAddress>City Center Plaza516 Main St.</ShipAddress>
<ShipCity>Elgin</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97827</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>HUNGC</CustomerID>
<EmployeeID>4</EmployeeID>
<OrderDate>1997-07-16T00:00:00</OrderDate>
<RequiredDate>1997-08-13T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-07-21T00:00:00">
<ShipVia>1</ShipVia>
<Freight>45.13</Freight>
<ShipName>Hungry Coyote Import Store</ShipName>
<ShipAddress>City Center Plaza516 Main St.</ShipAddress>
<ShipCity>Elgin</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97827</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>HUNGC</CustomerID>
<EmployeeID>8</EmployeeID>
<OrderDate>1997-09-08T00:00:00</OrderDate>
<RequiredDate>1997-10-06T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-10-15T00:00:00">
<ShipVia>1</ShipVia>
<Freight>111.29</Freight>
<ShipName>Hungry Coyote Import Store</ShipName>
<ShipAddress>City Center Plaza516 Main St.</ShipAddress>
<ShipCity>Elgin</ShipCity>
<ShipRegion>OR</ShipRegion>
<ShipPostalCode>97827</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>LAZYK</CustomerID>
<EmployeeID>1</EmployeeID>
<OrderDate>1997-03-21T00:00:00</OrderDate>
<RequiredDate>1997-04-18T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-04-10T00:00:00">
<ShipVia>3</ShipVia>
<Freight>7.48</Freight>
<ShipName>Lazy K Kountry Store</ShipName>
<ShipAddress>12 Orchestra Terrace</ShipAddress>
<ShipCity>Walla Walla</ShipCity>
<ShipRegion>WA</ShipRegion>
<ShipPostalCode>99362</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>LAZYK</CustomerID>
<EmployeeID>8</EmployeeID>
<OrderDate>1997-05-22T00:00:00</OrderDate>
<RequiredDate>1997-06-19T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-06-26T00:00:00">
<ShipVia>2</ShipVia>
<Freight>11.92</Freight>
<ShipName>Lazy K Kountry Store</ShipName>
<ShipAddress>12 Orchestra Terrace</ShipAddress>
<ShipCity>Walla Walla</ShipCity>
<ShipRegion>WA</ShipRegion>
<ShipPostalCode>99362</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>LETSS</CustomerID>
<EmployeeID>1</EmployeeID>
<OrderDate>1997-06-25T00:00:00</OrderDate>
<RequiredDate>1997-07-23T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-07-04T00:00:00">
<ShipVia>2</ShipVia>
<Freight>13.73</Freight>
<ShipName>Let's Stop N Shop</ShipName>
<ShipAddress>87 Polk St. Suite 5</ShipAddress>
<ShipCity>San Francisco</ShipCity>
<ShipRegion>CA</ShipRegion>
<ShipPostalCode>94117</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>LETSS</CustomerID>
<EmployeeID>8</EmployeeID>
<OrderDate>1997-10-27T00:00:00</OrderDate>
<RequiredDate>1997-11-24T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-11-05T00:00:00">
<ShipVia>2</ShipVia>
<Freight>51.44</Freight>
<ShipName>Let's Stop N Shop</ShipName>
<ShipAddress>87 Polk St. Suite 5</ShipAddress>
<ShipCity>San Francisco</ShipCity>
<ShipRegion>CA</ShipRegion>
<ShipPostalCode>94117</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>LETSS</CustomerID>
<EmployeeID>6</EmployeeID>
<OrderDate>1997-11-10T00:00:00</OrderDate>
<RequiredDate>1997-12-08T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1997-11-21T00:00:00">
<ShipVia>2</ShipVia>
<Freight>45.97</Freight>
<ShipName>Let's Stop N Shop</ShipName>
<ShipAddress>87 Polk St. Suite 5</ShipAddress>
<ShipCity>San Francisco</ShipCity>
<ShipRegion>CA</ShipRegion>
<ShipPostalCode>94117</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
<Order>
<CustomerID>LETSS</CustomerID>
<EmployeeID>4</EmployeeID>
<OrderDate>1998-02-12T00:00:00</OrderDate>
<RequiredDate>1998-03-12T00:00:00</RequiredDate>
<ShipInfo ShippedDate="1998-02-13T00:00:00">
<ShipVia>2</ShipVia>
<Freight>90.97</Freight>
<ShipName>Let's Stop N Shop</ShipName>
<ShipAddress>87 Polk St. Suite 5</ShipAddress>
<ShipCity>San Francisco</ShipCity>
<ShipRegion>CA</ShipRegion>
<ShipPostalCode>94117</ShipPostalCode>
<ShipCountry>USA</ShipCountry>
</ShipInfo>
</Order>
</Orders>
</Root>
Data.xml
<Root>
<TaxRate>7.25</TaxRate>
<Data>
<Category>A</Category>
<Quantity>3</Quantity>
<Price>24.50</Price>
</Data>
<Data>
<Category>B</Category>
<Quantity>1</Quantity>
<Price>89.99</Price>
</Data>
<Data>
<Category>A</Category>
<Quantity>5</Quantity>
<Price>4.95</Price>
</Data>
<Data>
<Category>A</Category>
<Quantity>3</Quantity>
<Price>66.00</Price>
</Data>
<Data>
<Category>B</Category>
<Quantity>10</Quantity>
<Price>.99</Price>
</Data>
<Data>
<Category>A</Category>
<Quantity>15</Quantity>
<Price>29.00</Price>
</Data>
<Data>
<Category>B</Category>
<Quantity>8</Quantity>
<Price>6.99</Price>
</Data>
</Root>
PurchaseOrder.xml
<?xml version="1.0"?>
<PurchaseOrderPurchaseOrderNumber="99503" OrderDate="1999-10-20">
<Address Type="Shipping">
<Name>Ellen Adams</Name>
<Street>123 Maple Street</Street>
<City>Mill Valley</City>
<State>CA</State>
<Zip>10999</Zip>
<Country>USA</Country>
</Address>
<Address Type="Billing">
<Name>Tai Yee</Name>
<Street>8 Oak Avenue</Street>
<City>Old Town</City>
<State>PA</State>
<Zip>95819</Zip>
<Country>USA</Country>
</Address>
<DeliveryNotes>Please leave packages in shed bydriveway.</DeliveryNotes>
<Items>
<Item PartNumber="872-AA">
<ProductName>Lawnmower</ProductName>
<Quantity>1</Quantity>
<USPrice>148.95</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
<Item PartNumber="926-AA">
<ProductName>Baby Monitor</ProductName>
<Quantity>2</Quantity>
<USPrice>39.98</USPrice>
<ShipDate>1999-05-21</ShipDate>
</Item>
</Items>
</PurchaseOrder>
PurchaseOrders.xml
<?xml version="1.0"?>
<PurchaseOrders>
<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
<Address Type="Shipping">
<Name>Ellen Adams</Name>
<Street>123 Maple Street</Street>
<City>Mill Valley</City>
<State>CA</State>
<Zip>10999</Zip>
<Country>USA</Country>
</Address>
<Address Type="Billing">
<Name>Tai Yee</Name>
<Street>8 Oak Avenue</Street>
<City>Old Town</City>
<State>PA</State>
<Zip>95819</Zip>
<Country>USA</Country>
</Address>
<DeliveryNotes>Please leave packages in shed bydriveway.</DeliveryNotes>
<Items>
<Item PartNumber="872-AA">
<ProductName>Lawnmower</ProductName>
<Quantity>1</Quantity>
<USPrice>148.95</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
<Item PartNumber="926-AA">
<ProductName>Baby Monitor</ProductName>
<Quantity>2</Quantity>
<USPrice>39.98</USPrice>
<ShipDate>1999-05-21</ShipDate>
</Item>
</Items>
</PurchaseOrder>
<PurchaseOrder PurchaseOrderNumber="99505" OrderDate="1999-10-22">
<Address Type="Shipping">
<Name>Cristian Osorio</Name>
<Street>456 Main Street</Street>
<City>Buffalo</City>
<State>NY</State>
<Zip>98112</Zip>
<Country>USA</Country>
</Address>
<Address Type="Billing">
<Name>Cristian Osorio</Name>
<Street>456 Main Street</Street>
<City>Buffalo</City>
<State>NY</State>
<Zip>98112</Zip>
<Country>USA</Country>
</Address>
<DeliveryNotes>Please notify me beforeshipping.</DeliveryNotes>
<Items>
<Item PartNumber="456-NM">
<ProductName>Power Supply</ProductName>
<Quantity>1</Quantity>
<USPrice>45.99</USPrice>
</Item>
</Items>
</PurchaseOrder>
<PurchaseOrder PurchaseOrderNumber="99504" OrderDate="1999-10-22">
<Address Type="Shipping">
<Name>Jessica Arnold</Name>
<Street>4055 Madison Ave</Street>
<City>Seattle</City>
<State>WA</State>
<Zip>98112</Zip>
<Country>USA</Country>
</Address>
<Address Type="Billing">
<Name>Jessica Arnold</Name>
<Street>4055 Madison Ave</Street>
<City>Buffalo</City>
<State>NY</State>
<Zip>98112</Zip>
<Country>USA</Country>
</Address>
<Items>
<Item PartNumber="898-AZ">
<ProductName>Computer Keyboard</ProductName>
<Quantity>1</Quantity>
<USPrice>29.99</USPrice>
</Item>
<Item PartNumber="898-AM">
<ProductName>Wireless Mouse</ProductName>
<Quantity>1</Quantity>
<USPrice>14.99</USPrice>
</Item>
</Items>
</PurchaseOrder>
</PurchaseOrders>
Test.xml
<?xml version="1.0"encoding="utf-8"?>
<!--This is a comment.-->
<?xml-stylesheet href='mystyle.css'title='Compact' type='text/css'?>
<Pubs>
<Book>
<Title>Artifacts of Roman Civilization</Title>
<Author>Moreno,Jordao</Author>
</Book>
<Book>
<Title>Midieval Tools and Implements</Title>
<Author>Gazit, Inbar</Author>
</Book>
</Pubs>
<!--This is another comment.-->