Ejemplo n.º 1
0
        private XMLNodeEX CheckSubNode(XMLNodeEX node, string name)
        {
            name = name.ToLower();

            if (node.Name.ToLower() == name)
            {
                return(node);
            }

            if (node.Nodes != null)
            {
                for (int i = 0; i < node.Nodes.Length; i++)
                {
                    XMLNodeEX subnode = node.Nodes[i];
                    if (subnode.Name.ToLower() == name)
                    {
                        return(subnode);
                    }
                    if (node.Nodes.Length > 0)
                    {
                        for (int j = 0; j < node.Nodes.Length; j++)
                        {
                            subnode = CheckSubNode(node.Nodes[i], name);
                            if (subnode != null)
                            {
                                return(subnode);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new node
 /// </summary>
 /// <param name="parent">Parent node</param>
 /// <param name="name">Name of the node</param>
 /// <param name="value">Value of the node</param>
 public XMLNodeEX(XMLNodeEX parent, string name, string value)
 {
     Name       = parent.Name + "\\" + name;
     _shortname = name;
     _parent    = parent;
     Value      = value;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds a node
 /// </summary>
 /// <param name="node">Node to be added</param>
 public void AddNode(XMLNodeEX node)
 {
     if (_nodes == null)
     {
         _nodes = new[] { node };
     }
     else
     {
         var tmp = new XMLNodeEX[_nodes.Length + 1];
         Array.Copy(_nodes, tmp, _nodes.Length);
         tmp[tmp.Length - 1] = node;
         _nodes = tmp;
     }
 }
Ejemplo n.º 4
0
        private string SubNodeData(XMLNodeEX node)
        {
            string xml = string.Empty;

            for (int i = 0; i < node.Nodes.Length; i++)
            {
                if (node.Nodes[i].Nodes.Length == 0)
                {
                    xml = string.Concat(xml,
                                        "<" + node.Nodes[i].ShortName + ">" + node.Nodes[i].Value + "</" + node.Nodes[i].ShortName + ">");
                }
                else
                {
                    xml = string.Concat(xml, "<" + node.Nodes[i].ShortName + ">" + SubNodeData(node.Nodes[i]) + "</" + node.Nodes[i].ShortName + ">");
                }
            }

            return(xml);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns an XMLNodeEX by it's name
 /// </summary>
 /// <param name="name">Name of the node to retrieve</param>
 /// <returns>Returns the node or null if not found</returns>
 public XMLNodeEX NodeByName(string name)
 {
     name = name.ToLower();
     for (int i = 0; i < _nodes.Length; i++)
     {
         if (_nodes[i].Name.ToLower() == name)
         {
             return(_nodes[i]);
         }
         if (_nodes[i].Nodes.Length > 0)
         {
             for (int j = 0; j < _nodes[i].Nodes.Length; j++)
             {
                 XMLNodeEX subnode = CheckSubNode(_nodes[i].Nodes[j], name);
                 if (subnode != null)
                 {
                     return(subnode);
                 }
             }
         }
     }
     return(null);
 }
Ejemplo n.º 6
0
        private void ReadStructure(MemoryStream ms)
        {
            // Create Base Node
            XMLNodeEX node = null;
            XMLNodeEX curn = null;

            // Create Reader Settings
            var ss = new XmlReaderSettings
            {
                IgnoreWhitespace = true,
                IgnoreComments   = false
            };

            // Create Reader
            XmlReader xr = XmlReader.Create(ms, ss);

            // Loop through nodes to create structure
            while (!xr.EOF)
            {
                xr.Read();
                switch (xr.NodeType)
                {
                case XmlNodeType.Element:
                    if (node == null)
                    {
                        node = new XMLNodeEX(xr.Name);
                        curn = node;
                        AddNode(node);
                    }
                    else
                    {
                        var subn = new XMLNodeEX(xr.Name, curn);
                        curn.AddNode(subn);
                        curn = subn;
                    }
                    break;

                case XmlNodeType.CDATA:
                case XmlNodeType.Text:
                    if (curn != null)
                    {
                        curn.Value = xr.Value;
                    }
                    break;

                case XmlNodeType.XmlDeclaration:
                case XmlNodeType.Comment:
                case XmlNodeType.Whitespace:
                case XmlNodeType.None:
                    // We do not care
                    break;

                case XmlNodeType.EndElement:
                    if (curn != null)
                    {
                        curn = curn.Parent;
                        if (curn == null)
                        {
                            node = null;
                        }
                    }
                    break;
                }
            }
        }
Ejemplo n.º 7
0
 internal XMLNodeEX(string name, XMLNodeEX parent)
 {
     Name       = parent.Name + "\\" + name;
     _shortname = name;
     _parent    = parent;
 }