Exemple #1
0
 //============================================================
 // <T>序列化内容到输出流内。</T>
 // <P>只处理结点类型数据。</P>
 //
 // @param output 输出流
 // @param element 元素对象
 //============================================================
 protected void InnerSerialize(IDataOutput output, FXmlElement element)
 {
     if (element.Type == EXmlElementType.Node)
     {
         output.WriteString(element.Name);
         output.WriteString(element.Text);
         if (element.HasAttribute())
         {
             output.WriteInt16((short)element.Attributes.Count);
             foreach (IStringPair pair in element.Attributes)
             {
                 output.WriteString(pair.Name);
                 output.WriteString(pair.Value);
             }
         }
         else
         {
             output.WriteInt16(0);
         }
         int nodeCount = element.ElementCount(EXmlElementType.Node);
         output.WriteInt16((short)nodeCount);
         if (nodeCount > 0)
         {
             foreach (FXmlElement child in element.Elements)
             {
                 if (child.Type == EXmlElementType.Node)
                 {
                     InnerSerialize(output, child);
                 }
             }
         }
     }
 }
Exemple #2
0
 //============================================================
 // <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;
             }
         }
     }
 }
Exemple #3
0
 //============================================================
 // <T>在元素列表尾部追加一个元素对象。</T>
 //
 // @param element 元素对象
 //============================================================
 public override void Push(FXmlElement element)
 {
     base.Push(element);
     if (element is FXmlNode)
     {
         Nodes.Push((FXmlNode)element);
     }
 }
Exemple #4
0
 //============================================================
 // <T>构造文档。</T>
 //
 // @param assembly 模块对象
 // @param name 资源名称
 //============================================================
 protected void InnerConstruct()
 {
     // 构造根节点
     _root           = new FXmlNode(RXml.ROOT_NAME);
     _root._document = this;
     // 构造根元素
     _element           = new FXmlElement();
     _element._document = this;
     _element.Push(_root);
 }
Exemple #5
0
        //============================================================
        // <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);
                    }
                }
            }
        }
Exemple #6
0
        //============================================================
        // <T>获得调试转储信息。</T>
        //
        // @param info 转储信息
        // @return 转储信息
        //============================================================
        public virtual FDump Dump(FDump info)
        {
            RDump.StartDump(info);
            FXmlElement parent = (FXmlElement)info.Instance;

            if (parent.HasElement())
            {
                foreach (FXmlElement element in parent.Elements)
                {
                    info.IncreaseDeep(element);
                    Dump(info);
                    info.DecreaseDeep();
                }
            }
            return(info);
        }
Exemple #7
0
 //============================================================
 // <T>生成XML字符串。</T>
 //
 // @param xml 字符串对象
 // @param element 元素对象
 //============================================================
 protected void InnerMakeXml(FString xml, FXmlElement element)
 {
     xml.Append("<");
     xml.Append(element.Name);
     if (element.HasAttribute())
     {
         foreach (IStringPair pair in element.Attributes)
         {
             xml.Append(" ");
             xml.Append(pair.Name);
             xml.Append("=\"");
             xml.Append(pair.Value);
             xml.Append("\"");
         }
     }
     if (element.HasElement())
     {
         xml.Append(">");
         xml.Append(element.Text);
         foreach (FXmlElement child in element.Elements)
         {
             InnerMakeXml(xml, child);
         }
         xml.Append("</");
         xml.Append(element.Name);
         xml.Append(">");
     }
     else
     {
         if (element.HasText())
         {
             xml.Append(">");
             xml.Append(element.Text);
             xml.Append("</");
             xml.Append(element.Name);
             xml.Append(">");
         }
         else
         {
             xml.Append("/>");
         }
     }
 }
Exemple #8
0
 //============================================================
 // <T>在元素列表尾部追加一个元素对象。</T>
 //
 // @param element 元素对象
 //============================================================
 public virtual void Push(FXmlElement element)
 {
     Elements.Push(element);
 }