Developer forum

Forum » PIM » Remove line break in feed

Remove line break in feed

Anders Ebdrup
Anders Ebdrup
Reply

Hello,

 

I am trying to create a xml feed, but the output starts with a line break and not the xml declaration which is not valid. How can I avoid having the first line break?

Please see the first lines of code here

@using Dynamicweb.Rendering;
@using Dynamicweb.Ecommerce.ProductCatalog;
@using Newtonsoft.Json;
@using System.Xml.Linq;
@inherits ViewModelTemplate<ProductListViewModel>
@functions
{
    public enum FieldType
    {
        System,
        Standard,
        Custom,
        CategoryField
    };

    public class Field
    {
        public string ID { get; set; }
        public FieldType FieldType { get; set; }
        public string Label { get; set; }

        public Field(string id, string label, FieldType type)
        {
            ID = id;
            Label = label;
            FieldType = type;
        }
    }

    public string GenerateXML()
    {
        var fields = GetFields();

        XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));

        var rootElement = new XElement("Root");

        foreach (ProductViewModel product in Model.Products)
        {
            ProcessProductXml(rootElement, fields, product);
        }

        xdoc.Add(rootElement);

        var wr = new System.IO.StringWriter();
        xdoc.Save(wr);
        return wr.ToString();
    }

Best regards, Anders


Replies

 
Anders Ebdrup
Anders Ebdrup
Reply

Never mind - I have found the issue! smiley

 

You must be logged in to post in the forum