-
Notifications
You must be signed in to change notification settings - Fork 4
consuming web log markup language blogml formatted content
Web Log Markup Language (BlogML) provides an open format derived from XML to store and restore the content of a blog. As the number of web log software platforms grows, there is a need to be able to import and export blog content in a portable, open format; and so the BlogML format was created to ease the difficulties faced when attempting to move web log content from one software platform to another.
The classes that together compose the implementation of BlogML are located in the Argotic.Syndication.Specialized namespace. The primary framework entity that you will use when working with BlogML formatted syndication resources is the BlogMLDocument class. This class implements the ISyndicationResource and IExtensibleSyndicationObject interfaces, and provides an API that maps closely to the syndication specification entities as well as methods for consuming and persisting syndicated web log content. The framework will by default automatically load any syndication extensions that are present in addition to the syndicated portable web log content and attempt to handle malformed XML data.
The BlogMLDocument class provides two ways of consuming syndicated content that conforms to the BlogML syndication format. The first way to consume BlogML portable web log content is to use the static Create method exposed by the BlogMLDocument class, which provides a means of quickly consuming portable web log content that is available at a given Uri:
using Argotic.Syndication.Specialized;
BlogMLDocument document = BlogMLDocument.Create(new Uri("http://www.example.org/blog/blogML.axd"));
foreach (BlogMLPost post in document.Posts)
{
if (post.ApprovalStatus == BlogMLApprovalStatus.Approved)
{
// Perform some processing on the blog post
}
}
The other way to consume BlogML formatted web log content is to use the overloaded Load method exposed by the BlogMLDocument class, which provides a means of consuming syndicated portable web log content from a variety of data sources such as IXPathNavigable, Stream, XmlReader, and Uri:
using System.IO;
using System.Xml;
using System.Xml.Xpath;
using Argotic.Syndication.Specialized;
BlogMLDocument document = new BlogMLDocument();
using (FileStream stream = new FileStream("SampleWeblogContent.xml", FileMode.Open, FileAccess.Read))
{
document.Load(stream);
}
document = new BlogMLDocument();
using (FileStream stream = new FileStream("SampleWeblogContent.xml", FileMode.Open, FileAccess.Read))
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create(stream, settings))
{
document.Load(reader);
}
}
document = new BlogMLDocument();
using (FileStream stream = new FileStream("SampleWeblogContent.xml", FileMode.Open, FileAccess.Read))
{
document.Load(new XPathDocument(stream));
}
Sample file that can be used with the above code example: [file:SampleWeblogContent.xml]