public void WriteBinaryXmlElement(BinaryXmlElement binElem)
 {
     this.Write(binElem.elementNameID);
     this.Write(binElem.elementValueID);
     this.Write(binElem.attributeCount);
     this.Write(binElem.attributeStartID);
     this.Write(binElem.childElementCount);
     this.Write(binElem.childElementStartID);
 }
 public void WriteBinaryXmlElement(BinaryXmlElement binElem)
 {
     this.Write(binElem.elementNameID);
     this.Write(binElem.elementValueID);
     this.Write(binElem.attributeCount);
     this.Write(binElem.attributeStartID);
     this.Write(binElem.childElementCount);
     this.Write(binElem.childElementStartID);
 }
        public void BuildBinXml(XmlElement elem, Dictionary<string, int> valuesToID, List<BinaryXmlElement> xmlElems, List<BinaryXmlAttribute> xmlAttrs, int childElemIndex = 0)
        {
            if (childElemIndex == 0)
            {
                xmlElems.Add(new BinaryXmlElement());
            }
            BinaryXmlElement binElem = new BinaryXmlElement();
            int currentIndex = xmlElems.Count - 1;

            // Element Name String
            if (!valuesToID.ContainsKey(elem.Name))
            {
                binElem.elementNameID = valuesToID.Count;
                valuesToID.Add(elem.Name, valuesToID.Count);
            }
            else
            {
                binElem.elementNameID = valuesToID[elem.Name];
            }

            binElem.attributeStartID = elem.Attributes.Count > 0 ? xmlAttrs.Count : 0;
            binElem.attributeCount = elem.Attributes.Count;
            foreach (XmlAttribute attr in elem.Attributes)
            {
                BinaryXmlAttribute binAttr = new BinaryXmlAttribute();

                // Attribute Name String
                if (!valuesToID.ContainsKey(attr.Name))
                {
                    binAttr.nameID = valuesToID.Count;
                    valuesToID.Add(attr.Name, valuesToID.Count);
                }
                else
                {
                    binAttr.nameID = valuesToID[attr.Name];
                }

                // Attribute Value String
                if (!valuesToID.ContainsKey(attr.Value))
                {
                    binAttr.valueID = valuesToID.Count;
                    valuesToID.Add(attr.Value, valuesToID.Count);
                }
                else
                {
                    binAttr.valueID = valuesToID[attr.Value];
                }

                xmlAttrs.Add(binAttr);
            }

            // Element Value or Child Elements
            // Set its childElementStartID to the next available index for binary xml elements
            // AKA the current count, will be overwritten if element actually has child nodes
            binElem.childElementStartID = xmlElems.Count;
            if (elem.HasChildNodes)
            {
                // Values inside of an element are considered child nodes like <element>ThisValue</element>
                // More Specifically they're called "XmlText" or Text Nodes
                if (elem.ChildNodes[0].NodeType == XmlNodeType.Text)
                {
                    //System.Windows.Forms.MessageBox.Show("daasda22222222222222222");
                    XmlText textNode = (XmlText)elem.ChildNodes[0];
                    if (textNode.Value != null)
                    {
                        if (!valuesToID.ContainsKey(textNode.Value))
                        {
                            binElem.elementValueID = valuesToID.Count;
                            valuesToID.Add(textNode.Value, valuesToID.Count);
                        }
                        else
                        {
                            binElem.elementValueID = valuesToID[textNode.Value];
                        }
                    }
                }
                else
                {
                    binElem.childElementStartID = xmlElems.Count;
                    binElem.childElementCount = elem.ChildNodes.Count;

                    xmlElems.AddRange(new BinaryXmlElement[elem.ChildNodes.Count]);
                    int i = binElem.childElementStartID;
                    foreach (XmlElement childElem in elem.ChildNodes)
                    {
                        BuildBinXml(childElem, valuesToID, xmlElems, xmlAttrs, i);
                        i++;
                    }
                }
            }

            // Update the xmlElems Entry
            if (childElemIndex == 0)
            {
                xmlElems[currentIndex] = binElem;
            }
            else
            {
                xmlElems[childElemIndex] = binElem;
            }
        }
Exemple #4
0
        public void BuildBinXml(XmlElement elem, Dictionary <string, int> valuesToID, List <BinaryXmlElement> xmlElems, List <BinaryXmlAttribute> xmlAttrs, int childElemIndex = 0)
        {
            if (childElemIndex == 0)
            {
                xmlElems.Add(new BinaryXmlElement());
            }
            BinaryXmlElement binElem = new BinaryXmlElement();
            int currentIndex         = xmlElems.Count - 1;

            // Element Name String
            if (!valuesToID.ContainsKey(elem.Name))
            {
                binElem.elementNameID = valuesToID.Count;
                valuesToID.Add(elem.Name, valuesToID.Count);
            }
            else
            {
                binElem.elementNameID = valuesToID[elem.Name];
            }

            binElem.attributeStartID = elem.Attributes.Count > 0 ? xmlAttrs.Count : 0;
            binElem.attributeCount   = elem.Attributes.Count;
            foreach (XmlAttribute attr in elem.Attributes)
            {
                BinaryXmlAttribute binAttr = new BinaryXmlAttribute();

                // Attribute Name String
                if (!valuesToID.ContainsKey(attr.Name))
                {
                    binAttr.nameID = valuesToID.Count;
                    valuesToID.Add(attr.Name, valuesToID.Count);
                }
                else
                {
                    binAttr.nameID = valuesToID[attr.Name];
                }

                // Attribute Value String
                if (!valuesToID.ContainsKey(attr.Value))
                {
                    binAttr.valueID = valuesToID.Count;
                    valuesToID.Add(attr.Value, valuesToID.Count);
                }
                else
                {
                    binAttr.valueID = valuesToID[attr.Value];
                }

                xmlAttrs.Add(binAttr);
            }

            // Element Value or Child Elements
            // Set its childElementStartID to the next available index for binary xml elements
            // AKA the current count, will be overwritten if element actually has child nodes
            binElem.childElementStartID = xmlElems.Count;
            if (elem.HasChildNodes)
            {
                // Values inside of an element are considered child nodes like <element>ThisValue</element>
                // More Specifically they're called "XmlText" or Text Nodes
                if (elem.ChildNodes[0].NodeType == XmlNodeType.Text)
                {
                    //System.Windows.Forms.MessageBox.Show("daasda22222222222222222");
                    XmlText textNode = (XmlText)elem.ChildNodes[0];
                    if (textNode.Value != null)
                    {
                        if (!valuesToID.ContainsKey(textNode.Value))
                        {
                            binElem.elementValueID = valuesToID.Count;
                            valuesToID.Add(textNode.Value, valuesToID.Count);
                        }
                        else
                        {
                            binElem.elementValueID = valuesToID[textNode.Value];
                        }
                    }
                }
                else
                {
                    binElem.childElementStartID = xmlElems.Count;
                    binElem.childElementCount   = elem.ChildNodes.Count;

                    xmlElems.AddRange(new BinaryXmlElement[elem.ChildNodes.Count]);
                    int i = binElem.childElementStartID;
                    foreach (XmlElement childElem in elem.ChildNodes)
                    {
                        BuildBinXml(childElem, valuesToID, xmlElems, xmlAttrs, i);
                        i++;
                    }
                }
            }

            // Update the xmlElems Entry
            if (childElemIndex == 0)
            {
                xmlElems[currentIndex] = binElem;
            }
            else
            {
                xmlElems[childElemIndex] = binElem;
            }
        }