/// <summary> /// creates an node by the given Configuration /// </summary> /// <param name="config">Config node</param> /// <returns>created xml Node</returns> private XmlNode createNodeFromConfig(PConfigContent config) { string name = config.getName(); if (name == "") { return(null); } XmlNode newNode = this.doc.CreateElement(this.getValidXmlName(name)); this.addAttribute(newNode, this.contentKey, config.getContent()); this.addAttribute(newNode, this.nameKey, name); if (config.ChildExists()) { List <string> childs = config.getContentAsList(); if (childs != null) { for (int i = 0; i < childs.Count; i++) { PConfigContent addConf = config.getChildByName(childs[i]); XmlNode addNode = this.createNodeFromConfig(addConf); if (addNode != null) { newNode.AppendChild(addNode); } } } } return(newNode); }
/// <summary> /// Maps recursiv the xml node to pconfig content /// </summary> /// <param name="xNode">current xml node</param> /// <param name="cNode">curren pConfigContent</param> private void mapNodeToConfig(XmlNode xNode, PConfigContent cNode) { // only valid if we have 2 attributes if (xNode != null && xNode.Attributes != null && xNode.Attributes.Count == 2) { XmlAttribute nameAttr = xNode.Attributes[this.nameKey]; XmlAttribute valueAttr = xNode.Attributes[this.contentKey]; if (nameAttr != null) { string content = nameAttr.InnerText; cNode.changeName(content); } if (valueAttr != null) { string content = valueAttr.InnerText; if (content != "") { cNode.Update(content); } } if (xNode.HasChildNodes) { for (int i = 0; i < xNode.ChildNodes.Count; i++) { PConfigContent subNode = cNode.addGroupChild(xNode.ChildNodes[i].Name); mapNodeToConfig(xNode.ChildNodes[i], subNode); } } } }
/// <summary> /// add a Configuration and fills /// the xml coument with content from this /// </summary> /// <param name="config"></param> public void addNodeByConfig(PConfigContent config) { XmlNode node = this.createNodeFromConfig(config); if (node != null) { this.doc.AppendChild(node); } }
/// <summary> /// try to read xml content and map these to /// pconfig properties /// </summary> /// <returns>null on mapping error</returns> public PConfigContent tryToReadConfig() { PConfigContent loadedConf = new PConfigContent(); if (this.loaded) { XmlNode first = this.doc.FirstChild; this.mapNodeToConfig(first, loadedConf); return(loadedConf); } return(null); }