tags:

views:

95

answers:

1

How can insert new line after each syndicationitem when using SynicationFeed class in dotnet 3.5?

when you see result of googlebot fetch (in webmasters), it its ONE LINE!!!!!!

A: 

When you create your XMLWriter you can pass into the constructor some XMLWriterSettings and set the indent property to true. This will format your code. Here is an example of the feed and item creation using the AtomFormatter. I have not populated the feed and items with any date for readability.

//Create your feed and fill with data
SyndicationFeed feed = new SyndicationFeed();

//Create an item and fill with data
SyndicationItem item = new SyndicationItem();

//Add item to list and add list to feed
List<SyndicationItem> items = new List<SyndicationItem>();
feed.Items = items;

//Create XML file and serialize feed with XMLWriterSettings to indent code
XmlWriter writer = XmlWriter.Create("D:\\MyTestFile.xml", new XmlWriterSettings { Indent = true });
Atom10FeedFormatter formatter = new Atom10FeedFormatter(feed);
formatter.WriteTo(writer);
writer.Close();
Cragly