SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 291 | Next

Scott Klein

"Professional LINQ"

That provides
the flexibility to use LINQ to XML to enumerate the results and write them to an XmlWriter, as shown in
the highlighted code.
IEnumerable xmlTree =
from el in StreamSalesOrders(@"C:\Wrox\LINQ\Chapter 8\Orders.xml")
where (DateTime)el.Attribute("Date") >= startDate
&& (DateTime)el.Attribute("Date") <= endDate
select new XElement("Order",
new XElement("SalesPerson",
(string)el.Parent.Element("Name")),
new XElement(el.Element("Amount")),
new XElement("OrderDate", el.Attribute("Date"))
)
);
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Indent = true;
using (XmlWriter xw = XmlWriter.Create(@"c:\Wrox\output.xml", xws))
{
xw.WriteStartElement("Root");
176
Chapter 8: Advanced LINQ to XML Programming Topics
foreach (XElement el in xmlTree)
el.WriteTo(xw);
xw.WriteEndElement();
}
You should get the same results as the previous example.
Summary
On the surface, LINQ to XML looks intimidating, but this and the previous three chapters should have
dispelled that vicious rumor.


Pages:
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6