Ejemplo n.º 1
0
        public void Read(BinaryReader input)
        {
            if (input.ReadByte() != 128)
            {
                throw new Exception("not a binary XML file");
            }
            BinaryXmlStringTable table = new BinaryXmlStringTable();

            table.Read(input);
            Root = new BinaryXmlNode();
            Root.Read(input, table);
        }
Ejemplo n.º 2
0
        public void Read(BinaryReader input, BinaryXmlStringTable table)
        {
            Name = table.getData(BinaryXmlFileHelpers.ReadPackedS32(input));
            //   Log.Write("<" + Name);
            Attributes = new Dictionary <string, string>();
            Children   = new List <BinaryXmlNode>();
            Value      = null;
            int num1 = input.ReadByte();

            if ((num1 & 1) == 1)
            {
                var offset = BinaryXmlFileHelpers.ReadPackedS32(input);
                Value = table.getData(offset);
            }
            if ((num1 & 2) == 2)
            {
                int attributeCount = BinaryXmlFileHelpers.ReadPackedS32(input);
                for (int index = 0; index < attributeCount; ++index)
                {
                    int keyTableOffset   = BinaryXmlFileHelpers.ReadPackedS32(input);
                    int valueTableOffset = BinaryXmlFileHelpers.ReadPackedS32(input);

                    var k = table.getData(keyTableOffset);
                    var v = table.getData(valueTableOffset);
                    //    Log.WriteLine($" \"{k}\"=\"{v}\"");
                    Attributes[k] = v;
                }
            }

            //Log.WriteLine(">");
            //if (Value != null)
            //    Log.WriteLine(Value);

            if ((num1 & 4) == 4) // has child nodes
            {
                int num3 = BinaryXmlFileHelpers.ReadPackedS32(input);
                for (int index = 0; index < num3; ++index)
                {
                    BinaryXmlNode binaryXmlNode = new BinaryXmlNode();
                    binaryXmlNode.Read(input, table);
                    Children.Add(binaryXmlNode);
                }
            }
            //Log.WriteLine("</" + Name + ">");
        }
Ejemplo n.º 3
0
        private static void WriteNode(XmlWriter xw, BinaryXmlNode node)
        {
            xw.WriteStartElement(node.Name);
            foreach (var kvp in node.Attributes)
            {
                xw.WriteAttributeString(kvp.Key, kvp.Value);
            }

            foreach (BinaryXmlNode node1 in node.Children)
            {
                WriteNode(xw, node1);
            }

            if (node.Value != null)
            {
                xw.WriteValue(node.Value);
            }
            xw.WriteEndElement();
        }