Beispiel #1
0
 internal ZXmlNode(ZXmlNode Parent, string Name)
 {
     this.Name		= XMT.GetValidNodeName(Name);
     _parent		= Parent;
     if (Parent != null)		_rootParent	= Parent._rootParent;
     _attrs		= new ZXmlAttributeList(this);
     _nodes		= new ZXmlNodeList(this);
 }
 private static void ReadAttributes(ZXmlNode Node, XmlReader rd)
 {
     for (int i = 0; i < rd.AttributeCount; i++)
     {
         rd.MoveToAttribute(i);
         Node.Attributes.Add(rd.Name, rd.Value);
     }
     rd.MoveToElement();
 }
        /// <summary>
        /// Parses XML string into node tree.
        /// </summary>
        /// <param name="S">The source XML string.</param>
        /// <returns>Returns the result tree of XML nodes.</returns>
        public static ZXmlNode ReadXML(string S)
        {
            var N	= new ZXmlNode(null, "r");
            int D	= -1;
            var CN	= N;

            var rd = XmlReader.Create(S);
            while (rd.Read())
            {
                switch (rd.NodeType)
                {
                    case XmlNodeType.Element:
                        if (rd.Depth > D)
                        {
                            CN = new ZXmlNode(N, rd.Name);
                           // CN = CN.Nodes.Add(rd.Name);
                            if (rd.HasAttributes)	ReadAttributes(CN, rd);
                            D = rd.Depth;
                        }
                        else
                        {
                        //    for (int i = 0; i < D-rd.Depth; i++)	CN = CN.Parent;
                        //	CN = CN.Parent.Nodes.Add(rd.Name);
                            CN = new ZXmlNode(N, rd.Name);
                            if (rd.HasAttributes)	ReadAttributes(CN, rd);
                            D = rd.Depth;
                        }
                        break;

                    case XmlNodeType.Text:
                        CN._text = rd.Value.ToCharArray();
                    break;
                }
            }
            return N;
        }
 internal ZXmlAttributeList(ZXmlNode Parent)
 {
     P = Parent;
 }
Beispiel #5
0
 /// <summary>
 /// Removes the specified node.
 /// </summary>
 /// <param name="Node">The node to remove.</param>
 public void Remove(ZXmlNode Node)
 {
     if (_nodes != null)	_nodes.Remove(Node);
 }
Beispiel #6
0
 /// <summary>
 /// Gets the index of the specified node.
 /// </summary>
 /// <param name="Node">The node to get index of.</param>
 /// <returns>Returns the index of the specified node.</returns>
 public int IndexOf(ZXmlNode Node)
 {
     if (_nodes == null)  return -1;		return _nodes.IndexOf(Node);
 }
Beispiel #7
0
 /// <summary>
 /// Inserts the specified array of nodes at the position with specified index.
 /// </summary>
 /// <param name="Index">Index of the position where specified array of nodes should be inserted.</param>
 /// <param name="Nodes">The array of nodes to insert.</param>
 public void Add(int Index, ZXmlNode[] Nodes)
 {
     if (_nodes == null)	 _nodes = new List<ZXmlNode>();
     Index = ZMath.GetBound(Index, 0, _nodes.Count);
     for (int i = 0; i < Nodes.Length; i++)
     {
         Nodes[i]._parent		= this.P;
         Nodes[i]._rootParent	= this.P.RootParent;
     }
     _nodes.InsertRange(Index, Nodes);
 }
Beispiel #8
0
 /// <summary>
 /// Adds the specified arrays of nodes at the end of this list.
 /// </summary>
 /// <param name="Nodes">The array of nodes to insert.</param>
 public void Add(ZXmlNode[] Nodes)
 {
     if (_nodes != null)  Add(_nodes.Count, Nodes);	Add(0, Nodes);
 }
Beispiel #9
0
 /// <summary>
 /// Inserts the specified node at the position with specified index.
 /// </summary>
 /// <param name="Index">Index of the position where specified node should be inserted.</param>
 /// <param name="Node">The node to insert.</param>
 /// <returns>Returns the inserted node.</returns>
 public ZXmlNode Add(int Index, ZXmlNode Node)
 {
     if (_nodes == null)	_nodes = new List<ZXmlNode>();
     Index = ZMath.GetBound(Index, 0, _nodes.Count);
     Node._parent		= this.P;
     Node._rootParent	= this.P.RootParent;
     _nodes.Insert(Index, Node);
     return Node;
 }
Beispiel #10
0
 /// <summary>
 /// Adds the specified node at the end of this list.
 /// </summary>
 /// <param name="Node">The node to add.</param>
 /// <returns>Returns the added node.</returns>
 public ZXmlNode Add(ZXmlNode Node)
 {
     if (_nodes != null)  return Add(_nodes.Count, Node);	return  Add(0, Node);
 }
Beispiel #11
0
 internal ZXmlNodeList(ZXmlNode Parent)
 {
     P = Parent;
 }