Fluent XML parsing in .NET

Ждал я, ждал и дождался. Dynamic object рулит.

// the variable xml contains the string text of an XML document
dynamic dx = new DynamicXml(xml);
Console.WriteLine(“PublicationDate=’{0}’”, dx.pubdate.Value);
Console.WriteLine(“BookCount=’{0}’”, dx.book.Count);
foreach (dynamic b in dx.book)
{
Console.WriteLine(“—– Begin Book —–”);
Console.WriteLine(“Price=’{0}’”, b.price.Value);
Console.WriteLine(“Title=’{0}’”, b.title.Value);
Console.WriteLine(“AuthorCount=’{0}’”, b.authors.author.Count);
foreach (dynamic a in b.authors.author)
{
Console.WriteLine(” —- Begin Author —-”);
Console.WriteLine(” EmailAddress=’{0}’”, a.email.address.Value);
Console.WriteLine(” FirstName=’{0}’”, a.name.first.Value);
Console.WriteLine(” MiddleName=’{0}’”, a.name.middle.Value);
Console.WriteLine(” LastName=’{0}’”, a.name.last.Value);
Console.WriteLine(” —– End Author —–”);
}
Console.WriteLine(“—— End Book ——”);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree