private XmlElement Add(string name, string value, IDictionary<string, string> attributes) { if (Value != null) throw new InvalidOperationException("XML Element " + Name + " has a text value: it cannot contain child elements"); var child = new XmlElement(this) { Name = name, Value = value, Attributes = attributes }; Children.Add(child); return child; }
public XmlElement GenerateXML() { var post = new XmlElement { Name = "item" }; post.Add("title").CData(Title).Up() .Add("description", Description).Up() .Add("pubDate", Date.ToString()).Up() .Add("content:encoded").CData(Content).Up() .Add("wp:post_id", Id).Up() .Add("wp:post_date", Date.ToString()).Up() .Add("wp:post_date_gmt", Date.ToUniversalTime().ToString()).Up() .Add("wp:post_type", "post").Up() .Add("wp:status", Status).Up(); foreach (var tag in Tags) post.Add("category", new { nicename = tag.Slug, domain = "post_tag" }) .CData(tag.Name); foreach (var cat in Categories) post.Add("category", new { nicename = cat.NiceName, domain = "category"}) .CData(cat.Name); return post; }
protected AbstractXmlElement(XmlElement parent = null) { Parent = parent; }
public XmlElement(XmlElement parent = null) : base(parent) { Children = new List<IXmlElement>(); Attributes = new Dictionary<string, string>(); }
public CDataElement(XmlElement parent = null) : base(parent) { }
private static string GetAttributes(XmlElement e) { return e.Attributes.Aggregate(" ", (current, attr) => current + (attr.Key + "=\"" + attr.Value + "\" ")); }
public XmlElement Begin(string rootElementName) { RootElement = new XmlElement { Name = rootElementName }; return RootElement; }
private string GetAttributes(XmlElement e) { string s = " "; foreach (var attr in e.Attributes) s += attr.Key + "=\"" + attr.Value + "\" "; return s; }
public AbstractXmlElement(XmlElement parent = null) { Parent = parent; }