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

                return(true);
            }
Beispiel #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, BMLString.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 += BMLString.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);
        }
Beispiel #3
0
            public bool ReadXML(XmlElement ele, u32 depth)
            {
                bool valid = true;

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

                if (ele.HasAttributes)
                {
                    if (ele.Attributes.Count > 0xFF)
                    {
                        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 BMLString.Ref(BMLString.DecodeXml(xnode.Value), false);
                            End2  = new BMLString.Ref("\r\n", false);

                            break;

                        case XmlNodeType.Comment:
                            // Could be added as Inner/End2, but not required
                            break;

                        default:
                            break;
                        }
                    }
                }

                bool last_child = !HasElementSibling(ele);

                Fixup(last_child);

                return(valid);
            }