public virtual void prepareData() { if (MoodleXmlElementAttribute.get(this.GetType()).HasFiles) { var images = this.HtmlNode.Descendants("img"); foreach (HtmlNode img in images) { FileElement file = new FileElement(); file.HtmlNode = img; this.FileElements.Add(file); } } }
private bool notifyRelatedElementProperties(Type parentType, MoodleXmlElement parentElement, MoodleXmlElement child) { PropertyInfo[] properties = parentType.GetProperties(); bool found = false; foreach (PropertyInfo property in properties) { MoodleXmlElementAttribute xmlAttributes = MoodleXmlElementAttribute.get(property); if (xmlAttributes != null && xmlAttributes.Children == true) { List <MoodleXmlElement> includedElements = (List <MoodleXmlElement>)property.GetValue(parentElement); includedElements.Add(child); found = true; break; } } return(found); }
public virtual XmlElement toXml(XmlDocument doc) { this.doc = doc; this.prepareData(); Type thisType = this.GetType(); string thisElementNodeName = MoodleXmlElementAttribute.get(thisType).Name.ToLower(); this.xmlElement = doc.CreateElement(thisElementNodeName); PropertyInfo[] thisProperties = thisType.GetProperties(); foreach (PropertyInfo thisProperty in thisProperties) { if (Attribute.IsDefined(thisProperty, typeof(MoodleXmlElementAttribute))) { MoodleXmlElementAttribute thisPropertyAttribute = MoodleXmlElementAttribute.get(thisProperty); this.reactToAttribute(thisPropertyAttribute, thisProperty); } } return(this.xmlElement); }
private void reactToAttribute(MoodleXmlElementAttribute attribute, PropertyInfo property) { if (attribute.Attr) { this.xmlElement.SetAttribute(property.Name.ToLower(), property.GetValue(this).ToString()); } if (attribute.Children) { List <MoodleXmlElement> children = (List <MoodleXmlElement>)property.GetValue(this); foreach (MoodleXmlElement child in children) { if (child != null) { XmlElement el = child.toXml(this.doc); if (el != null) { this.xmlElement.AppendChild(el); } } } } if (attribute.Node) { MoodleXmlElement childNode = (MoodleXmlElement)property.GetValue(this); this.xmlElement.AppendChild(childNode.toXml(this.doc)); } if (attribute.Content) { Text textElement = (Text)this; XmlCDataSection cdata = this.doc.CreateCDataSection(textElement.Content); this.xmlElement.AppendChild(cdata); } }