示例#1
0
            public bool ReadXML(string str_name, string str_value)
            {
                Name  = new AlienString.Ref(str_name, true);
                Value = new AlienString.Ref(AlienString.DecodeXml(str_value), true);

                return(true);
            }
示例#2
0
        // xxxx todo refactor
        private string DumpNode(Node n, int depth = 0)
        {
            string d       = "";
            bool   ignored = (depth == 0 && n.Attributes.Count == 0);

            if (!ignored)
            {
                d += String.Format("<{0}", n.Text.value);

                foreach (Attribute a in n.Attributes)
                {
                    // Now encodes XML entities (value)
                    d += String.Format(" {0}=\"{1}\"", a.Name.value, AlienString.EncodeXml(a.Value.value));
                }
            }

            if (n.Nodes.Count > 0)
            {
                if (!ignored)
                {
                    if (depth == 0)
                    {
                        // first xml tag must end in matching <? tags ?>
                        d += "?";
                    }

                    d += ">";

                    if (n.End != null)
                    {
                        d += n.End.value;
                    }
                }

                if (n.Inner != null && n.Inner.value.Length != 0)
                {
                    // Now encodes XML entities
                    d += AlienString.EncodeXml(n.Inner.value);
                }

                foreach (Node node in n.Nodes)
                {
                    d += DumpNode(node, depth + 1);
                }

                // uh, the first xml tag doesn't need to close
                if (depth != 0)
                {
                    d += String.Format("</{0}>", n.Text.value);

                    if (n.End2 != null)
                    {
                        d += n.End2.value;
                    }
                }
            }
            else if (!ignored)
            {
                if (n.Inner != null && n.Inner.value.Length != 0)
                {
                    d += ">";
                    d += n.Inner.value;
                    d += String.Format("</{0}>", n.Text.value);
                    d += n.End2.value;
                }
                else
                {
                    // <tag /> and <tag a="b" />
                    if (n.Attributes.Count > 0)
                    {
                        d += " ";
                    }

                    d += "/>";

                    if (n.End != null)
                    {
                        d += n.End.value;
                    }
                    if (n.End2 != null)
                    {
                        d += n.End2.value;
                    }
                }
            }

            return(d);
        }
示例#3
0
            public bool ReadXML(XmlElement ele, u32 depth)
            {
                bool valid = true;

                Depth = depth;
                Text  = new AlienString.Ref(ele.Name, true);

                if (ele.HasAttributes)
                {
                    if (ele.Attributes.Count > 0xFF)
                    {
                        //Console.WriteLine("Too many attributes for {0}", Text.value);
                        valid = false;
                        return(valid);
                    }

                    foreach (XmlAttribute attr in ele.Attributes)
                    {
                        Attribute a = new Attribute();
                        a.ReadXML(attr.Name, attr.Value);
                        Attributes.Add(a);
                    }
                }

                if (ele.HasChildNodes)
                {
                    // inner text is treated as a special text node, so it has children.. (YIKES)

                    foreach (XmlNode xnode in ele.ChildNodes)
                    {
                        // special parser requirements

                        switch (xnode.NodeType)
                        {
                        case XmlNodeType.Element:

                            XmlElement child = (xnode as XmlElement);

                            Node nchild = new Node();

                            valid &= nchild.ReadXML(child, depth + 1);

                            if (valid)
                            {
                                Nodes.Add(nchild);
                            }

                            break;

                        case XmlNodeType.Text:

                            Inner = new AlienString.Ref(AlienString.DecodeXml(xnode.Value), false);
                            End2  = new AlienString.Ref("\r\n", false);

                            break;

                        case XmlNodeType.Comment:

                            // Could be added as Inner/End2, but not required
                            //Console.WriteLine("Found XML comment - skipping it");

                            break;

                        default:
                            // Console.WriteLine("XmlNodeType not handled - skipping it");
                            break;
                        }
                    }
                }

                bool last_child = !HasElementSibling(ele);

                Fixup(last_child);

                return(valid);
            }