//============================================================ // <T>在当前元素下,创建一个节点对象。</T> // // @param name 节点名称 // @param attributes 属性列表 // @return 节点对象 //============================================================ public virtual FXmlNode CreateNode(string name, FAttributes attributes) { FXmlNode node = _document.NodeFactory.CreateNode(name, attributes); Elements.Push(node); return(node); }
//============================================================ // <T>在当前元素下,创建一个节点对象。</T> // // @param name 节点名称 // @param attributes 属性列表 // @return 节点对象 //============================================================ public override FXmlNode CreateNode(string name, FAttributes attributes) { FXmlNode node = base.CreateNode(name, attributes); Nodes.Push(node); return(node); }
//============================================================ // <T>创建文档节点。</T> // // @param name 节点名称 // @param attributes 属性列表 // @return 文档节点 //============================================================ public FXmlNode CreateNode(string name, FAttributes attributes) { FXmlNode node = new FXmlNode(name, attributes); node._document = _document; return(node); }
protected void Construct() { _heads = new FAttributes(); _parameters = new FAttributes(); _values = new FAttributes(); ResetHeads(); }
//============================================================ // <T>同步元素列表到文档元素中。</T> // // @param parent 元素对象 // @param elements 元素列表 //============================================================ internal static void SyncNodeFromElements(FXmlElement parent, XmlNodeList elements) { if ((null != parent) && (null != elements)) { // 同步节点 foreach (XmlNode element in elements) { if (element.NodeType == XmlNodeType.Element) { // 处理元素节点 string name = element.Name; FXmlElement node = null; FAttributes nodeAttrs = new FAttributes(); // 同步属性 XmlAttributeCollection eattrs = element.Attributes; if (null != eattrs) { foreach (XmlAttribute attr in eattrs) { nodeAttrs[attr.Name] = attr.Value; } } // 设置文本 bool hasChild = true; if (1 == element.ChildNodes.Count) { XmlNode child = element.FirstChild; if (child.NodeType == XmlNodeType.Text) { node = parent.CreateNode(name, nodeAttrs); node._type = EXmlElementType.Node; node.Text = child.Value; hasChild = false; } else if (child.NodeType == XmlNodeType.CDATA) { node = parent.CreateNode(name, nodeAttrs); node._type = EXmlElementType.Node; node.Text = child.Value; hasChild = false; } } if (null == node) { node = parent.CreateNode(name, nodeAttrs); } if (hasChild && (element.ChildNodes.Count > 0)) { SyncNodeFromElements(node, element.ChildNodes); } } else if (element.NodeType == XmlNodeType.Comment) { // 处理注释节点 parent.CreateComment().Text = element.Value; } } } }
//============================================================ // <T>从文档节点中建立属性表。</T> // // @param parent 文档元素 // @param attributes 属性列表 //============================================================ public static void BuildAttributes(FXmlNode parent, FAttributes attributes) { if ((parent != null) && parent.HasNode()) { foreach (FXmlNode node in parent.Nodes) { attributes[node.Name] = node.Text; } } }
//============================================================ // <T>同步文档元素到元素对象中。</T> // // @param node 文档元素 // @param element 元素对象 //============================================================ internal static void SyncElementFromNode(FXmlElement node, XmlNode element) { XmlDocument doc = element.OwnerDocument; // 设置元素内容 if (node._type == EXmlElementType.Data) { element.AppendChild(doc.CreateTextNode(node.Text)); return; } else if (!RString.IsEmpty(node.Text)) { element.AppendChild(doc.CreateTextNode(node.Text)); } // 同步属性列表 FAttributes attrs = node.Attributes; if (attrs != null) { foreach (IStringPair pair in attrs) { XmlAttribute xattr = doc.CreateAttribute(pair.Name); xattr.Value = pair.Value; element.Attributes.Append(xattr); } } // 同步元素列表 if (node.HasElement()) { foreach (FXmlElement nodeElement in node.Elements) { if (nodeElement is FXmlComment) { element.AppendChild(doc.CreateComment(nodeElement.Text)); } else if (nodeElement._type == EXmlElementType.Data) { element.AppendChild(doc.CreateCDataSection(nodeElement.Text)); } else { XmlNode celement = doc.CreateElement(nodeElement.Name); element.AppendChild(celement); SyncElementFromNode(nodeElement, celement); } } } }
//============================================================ // <T>构造文档节点。</T> // // @param name 节点名称 // @param attributes 属性列表 //============================================================ public FXmlNode(string name, FAttributes attributes) : base(name, attributes) { }
//============================================================ // <T>构造文档元素。</T> // // @param name 名称 // @param attributes 属性集合 //============================================================ public FXmlElement(string name, FAttributes attributes) { _name = name; _attributes = attributes; }
protected void Construct() { _heads = new FAttributes(); _parameters = new FAttributes(); }