using System.Xml; using VEPROMS.CSLA.Library; namespace Volian.Print.Library { public class CPSGen { public vlnParagraph MyVlnParagraph { get; set; } public CPSGen(vlnParagraph myParagraph) { MyVlnParagraph = myParagraph; } public void Generate(string fileName) { XmlDocument xd = new XmlDocument(); XmlElement parent = xd.AppendChild(xd.CreateElement("Items")) as XmlElement; Generate(0, 0,parent, MyVlnParagraph); xd.Save(fileName); } public void Generate(int level,int fromType,XmlElement parent, vlnParagraph para) { ItemInfo itm = para.MyItemInfo; XmlElement xe = parent.AppendChild(parent.OwnerDocument.CreateElement("Item")) as XmlElement; AddAttribute(xe, "Level", level); AddAttribute(xe, "FromType", fromType); AddAttribute(xe, "Ordinal", itm.Ordinal); AddAttribute(xe, "ParentID", (itm.ActiveParent as ItemInfo).ItemID); AddAttribute(xe, "ItemID", itm.ItemID); AddAttribute(xe, "PreviousID", itm.PreviousID); AddAttribute(xe, "ContentID", itm.ContentID); AddAttribute(xe, "DTS", itm.MyContent.DTS); AddAttribute(xe, "UserID", itm.MyContent.UserID); AddAttribute(xe, "Number", itm.MyContent.Number); AddAttribute(xe, "Text", itm.MyContent.Text); AddAttribute(xe, "Type", itm.MyContent.Type); AddAttribute(xe, "FormatID", itm.MyContent.FormatID); AddAttribute(xe, "Config", itm.MyContent.Config); AddAttribute(xe, "Rtf", para.Rtf); AddChildren(level,0, parent, "ChildrenAbove", para.ChildrenAbove); AddChildren(level,0, parent, "ChildrenLeft", para.ChildrenLeft); AddChildren(level,0, parent, "ChildrenRight", para.ChildrenRight); AddChildren(level,0, parent, "ChildrenBelow", para.ChildrenBelow); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping fromType and name for Debugging")] private void AddChildren(int level, int fromType, XmlElement parent, string name, vlnParagraphs children) { if (children == null || children.Count == 0) return; foreach(vlnParagraph child in children) { Generate(level+1,0,parent,child); } } private void AddAttribute(XmlElement xe, string attr, object val) { if (val == null) return; XmlAttribute xa = xe.OwnerDocument.CreateAttribute(attr); xa.Value = val.ToString(); xe.Attributes.Append(xa); } } }