private void ParseList(XmlBinaryNode listNode)
 {
     if (offset >= xmlDoc.Length)
     {
         return;
     }
     while (xmlDoc[offset] != XmlBinaryNodeType.EndListText && xmlDoc[offset] != XmlBinaryNodeType.EndListTextWithEndElement)
     {
         ParseContentNode(listNode);
         if (offset >= xmlDoc.Length)
         {
             return;
         }
     }
     listNode.AddChild(new XmlBinaryNode(xmlDoc[offset], depth));
     offset++; // EndListText
 }
Exemplo n.º 2
0
 private void Parse(ref XmlBinaryNode parent, bool insideAttribute, bool insideArray)
 {
     if (offset >= xmlDoc.Length) return;
     bool first = true;
     while (offset < xmlDoc.Length)
     {
         if (!first && insideAttribute)
         {
             return;
         }
         first = false;
         byte nodeType = xmlDoc[offset];
         if (XmlBinaryNodeType.IsTextNode(nodeType) || XmlBinaryNodeType.IsTextNodeWithEndElement(nodeType))
         {
             ParseContentNode(parent);
             if (XmlBinaryNodeType.IsTextNodeWithEndElement(nodeType))
             {
                 depth--;
                 return;
             }
         }
         else
         {
             offset++;
             XmlBinaryNode newNode = new XmlBinaryNode(nodeType, depth);
             if (parent == null)
             {
                 parent = newNode;
             }
             else
             {
                 parent.AddChild(newNode);
             }
             switch (nodeType)
             {
                 case XmlBinaryNodeType.EndElement:
                     depth--;
                     return;
                 case XmlBinaryNodeType.Comment:
                     newNode.Text = ReadString(0);
                     break;
                 case XmlBinaryNodeType.ShortElement:
                 case XmlBinaryNodeType.ShortDictionaryElement:
                 case XmlBinaryNodeType.Element:
                 case XmlBinaryNodeType.DictionaryElement:
                     {
                         bool isDictionaryElement = XmlBinaryNodeType.IsDictionaryElementNode(nodeType);
                         bool isShortElement = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                         if (!isShortElement)
                         {
                             newNode.Prefix = ReadString(0);
                         }
                         if (isDictionaryElement)
                         {
                             newNode.DictionaryLocalName = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.LocalName = ReadString(0);
                         }
                         int oldDepth = depth;
                         depth++;
                         Parse(ref newNode);
                         if (depth != oldDepth) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                         if (insideArray)
                         {
                             return;
                         }
                     }
                     break;
                 case XmlBinaryNodeType.PrefixElementA:
                 case XmlBinaryNodeType.PrefixElementB:
                 case XmlBinaryNodeType.PrefixElementC:
                 case XmlBinaryNodeType.PrefixElementD:
                 case XmlBinaryNodeType.PrefixElementE:
                 case XmlBinaryNodeType.PrefixElementF:
                 case XmlBinaryNodeType.PrefixElementG:
                 case XmlBinaryNodeType.PrefixElementH:
                 case XmlBinaryNodeType.PrefixElementI:
                 case XmlBinaryNodeType.PrefixElementJ:
                 case XmlBinaryNodeType.PrefixElementK:
                 case XmlBinaryNodeType.PrefixElementL:
                 case XmlBinaryNodeType.PrefixElementM:
                 case XmlBinaryNodeType.PrefixElementN:
                 case XmlBinaryNodeType.PrefixElementO:
                 case XmlBinaryNodeType.PrefixElementP:
                 case XmlBinaryNodeType.PrefixElementQ:
                 case XmlBinaryNodeType.PrefixElementR:
                 case XmlBinaryNodeType.PrefixElementS:
                 case XmlBinaryNodeType.PrefixElementT:
                 case XmlBinaryNodeType.PrefixElementU:
                 case XmlBinaryNodeType.PrefixElementV:
                 case XmlBinaryNodeType.PrefixElementW:
                 case XmlBinaryNodeType.PrefixElementX:
                 case XmlBinaryNodeType.PrefixElementY:
                 case XmlBinaryNodeType.PrefixElementZ:
                 case XmlBinaryNodeType.PrefixDictionaryElementA:
                 case XmlBinaryNodeType.PrefixDictionaryElementB:
                 case XmlBinaryNodeType.PrefixDictionaryElementC:
                 case XmlBinaryNodeType.PrefixDictionaryElementD:
                 case XmlBinaryNodeType.PrefixDictionaryElementE:
                 case XmlBinaryNodeType.PrefixDictionaryElementF:
                 case XmlBinaryNodeType.PrefixDictionaryElementG:
                 case XmlBinaryNodeType.PrefixDictionaryElementH:
                 case XmlBinaryNodeType.PrefixDictionaryElementI:
                 case XmlBinaryNodeType.PrefixDictionaryElementJ:
                 case XmlBinaryNodeType.PrefixDictionaryElementK:
                 case XmlBinaryNodeType.PrefixDictionaryElementL:
                 case XmlBinaryNodeType.PrefixDictionaryElementM:
                 case XmlBinaryNodeType.PrefixDictionaryElementN:
                 case XmlBinaryNodeType.PrefixDictionaryElementO:
                 case XmlBinaryNodeType.PrefixDictionaryElementP:
                 case XmlBinaryNodeType.PrefixDictionaryElementQ:
                 case XmlBinaryNodeType.PrefixDictionaryElementR:
                 case XmlBinaryNodeType.PrefixDictionaryElementS:
                 case XmlBinaryNodeType.PrefixDictionaryElementT:
                 case XmlBinaryNodeType.PrefixDictionaryElementU:
                 case XmlBinaryNodeType.PrefixDictionaryElementV:
                 case XmlBinaryNodeType.PrefixDictionaryElementW:
                 case XmlBinaryNodeType.PrefixDictionaryElementX:
                 case XmlBinaryNodeType.PrefixDictionaryElementY:
                 case XmlBinaryNodeType.PrefixDictionaryElementZ:
                     {
                         char prefixLetter;
                         bool isDictionaryElement = XmlBinaryNodeType.IsDictionaryElementNode(nodeType);
                         prefixLetter = (char)((int)'a' + (int)nodeType - (int)(isDictionaryElement ? XmlBinaryNodeType.PrefixDictionaryElementA : XmlBinaryNodeType.PrefixElementA));
                         newNode.Prefix = new string(prefixLetter, 1);
                         if (isDictionaryElement)
                         {
                             newNode.DictionaryLocalName = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.LocalName = ReadString(0);
                         }
                         int oldDepth = depth;
                         depth++;
                         Parse(ref newNode);
                         if (depth != oldDepth) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                         if (insideArray)
                         {
                             return;
                         }
                     }
                     break;
                 case XmlBinaryNodeType.ShortAttribute:
                 case XmlBinaryNodeType.ShortDictionaryAttribute:
                 case XmlBinaryNodeType.Attribute:
                 case XmlBinaryNodeType.DictionaryAttribute:
                     {
                         bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                         bool isShortAttribute = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                         if (!isShortAttribute)
                         {
                             newNode.Prefix = ReadString(0);
                         }
                         if (isDictionaryAttribute)
                         {
                             newNode.DictionaryLocalName = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.LocalName = ReadString(0);
                         }
                         int oldDepth = depth;
                         depth++;
                         Parse(ref newNode, true);
                         if (depth != (oldDepth + 1)) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                         depth--;
                         if (newNode.Children.Count != 1)
                         {
                             throw new ArgumentException("Error, attribute nodes must have exactly one child, at offset " + offset);
                         }
                     }
                     break;
                 case XmlBinaryNodeType.ShortXmlnsAttribute:
                 case XmlBinaryNodeType.ShortDictionaryXmlnsAttribute:
                 case XmlBinaryNodeType.XmlnsAttribute:
                 case XmlBinaryNodeType.DictionaryXmlnsAttribute:
                     {
                         bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                         bool isShortAttribute = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                         if (!isShortAttribute)
                         {
                             newNode.Prefix = ReadString(0);
                         }
                         if (isDictionaryAttribute)
                         {
                             newNode.DictionaryNamespaceURI = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.NamespaceURI = ReadString(0);
                         }
                     }
                     break;
                 case XmlBinaryNodeType.PrefixAttributeA:
                 case XmlBinaryNodeType.PrefixAttributeB:
                 case XmlBinaryNodeType.PrefixAttributeC:
                 case XmlBinaryNodeType.PrefixAttributeD:
                 case XmlBinaryNodeType.PrefixAttributeE:
                 case XmlBinaryNodeType.PrefixAttributeF:
                 case XmlBinaryNodeType.PrefixAttributeG:
                 case XmlBinaryNodeType.PrefixAttributeH:
                 case XmlBinaryNodeType.PrefixAttributeI:
                 case XmlBinaryNodeType.PrefixAttributeJ:
                 case XmlBinaryNodeType.PrefixAttributeK:
                 case XmlBinaryNodeType.PrefixAttributeL:
                 case XmlBinaryNodeType.PrefixAttributeM:
                 case XmlBinaryNodeType.PrefixAttributeN:
                 case XmlBinaryNodeType.PrefixAttributeO:
                 case XmlBinaryNodeType.PrefixAttributeP:
                 case XmlBinaryNodeType.PrefixAttributeQ:
                 case XmlBinaryNodeType.PrefixAttributeR:
                 case XmlBinaryNodeType.PrefixAttributeS:
                 case XmlBinaryNodeType.PrefixAttributeT:
                 case XmlBinaryNodeType.PrefixAttributeU:
                 case XmlBinaryNodeType.PrefixAttributeV:
                 case XmlBinaryNodeType.PrefixAttributeW:
                 case XmlBinaryNodeType.PrefixAttributeX:
                 case XmlBinaryNodeType.PrefixAttributeY:
                 case XmlBinaryNodeType.PrefixAttributeZ:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeA:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeB:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeC:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeD:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeE:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeF:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeG:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeH:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeI:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeJ:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeK:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeL:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeM:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeN:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeO:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeP:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeQ:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeR:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeS:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeT:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeU:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeV:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeW:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeX:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeY:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeZ:
                     {
                         char prefixLetter;
                         bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                         prefixLetter = (char)((int)'a' + (int)nodeType - (int)(isDictionaryAttribute ? XmlBinaryNodeType.PrefixDictionaryAttributeA : XmlBinaryNodeType.PrefixAttributeA));
                         newNode.Prefix = new string(prefixLetter, 1);
                         if (isDictionaryAttribute)
                         {
                             newNode.DictionaryLocalName = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.LocalName = ReadString(0);
                         }
                         int oldDepth = depth;
                         depth++;
                         Parse(ref newNode, true);
                         if (depth != (oldDepth + 1)) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                         depth--;
                         if (newNode.Children.Count != 1)
                         {
                             throw new ArgumentException("Error, attribute nodes must have exactly one child, at offset " + offset);
                         }
                     }
                     break;
                 case XmlBinaryNodeType.Array:
                     {
                         int oldDepth = depth;
                         depth++;
                         ParseArray(newNode);
                         if (depth != oldDepth) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                     }
                     break;
                 default:
                     throw new ArgumentException(String.Format("Error, the test is not ready to handle the type {0:X2} ({1}) yet", nodeType, XmlBinaryNodeType.GetNodeName(nodeType)));
             }
         }
     }
 }
Exemplo n.º 3
0
 private void ParseList(XmlBinaryNode listNode)
 {
     if (offset >= xmlDoc.Length) return;
     while (xmlDoc[offset] != XmlBinaryNodeType.EndListText && xmlDoc[offset] != XmlBinaryNodeType.EndListTextWithEndElement)
     {
         ParseContentNode(listNode);
         if (offset >= xmlDoc.Length) return;
     }
     listNode.AddChild(new XmlBinaryNode(xmlDoc[offset], depth));
     offset++; // EndListText
 }
Exemplo n.º 4
0
 private void ParseContentNode(XmlBinaryNode parent)
 {
     byte nodeType = xmlDoc[offset];
     offset++;
     XmlBinaryNode newNode = new XmlBinaryNode(nodeType, depth);
     parent.AddChild(newNode);
     switch (nodeType)
     {
         case XmlBinaryNodeType.Chars8Text:
         case XmlBinaryNodeType.Chars8TextWithEndElement:
             newNode.Text = ReadString(8);
             break;
         case XmlBinaryNodeType.Chars16Text:
         case XmlBinaryNodeType.Chars16TextWithEndElement:
             newNode.Text = ReadString(16);
             break;
         case XmlBinaryNodeType.Chars32Text:
         case XmlBinaryNodeType.Chars32TextWithEndElement:
             newNode.Text = ReadString(32);
             break;
         case XmlBinaryNodeType.UnicodeChars8Text:
         case XmlBinaryNodeType.UnicodeChars8TextWithEndElement:
         case XmlBinaryNodeType.UnicodeChars16Text:
         case XmlBinaryNodeType.UnicodeChars16TextWithEndElement:
         case XmlBinaryNodeType.UnicodeChars32Text:
         case XmlBinaryNodeType.UnicodeChars32TextWithEndElement:
             {
                 int unicodeTextLenSize = 0;
                 switch (nodeType)
                 {
                     case XmlBinaryNodeType.UnicodeChars8Text:
                     case XmlBinaryNodeType.UnicodeChars8TextWithEndElement:
                         unicodeTextLenSize = 1;
                         break;
                     case XmlBinaryNodeType.UnicodeChars16Text:
                     case XmlBinaryNodeType.UnicodeChars16TextWithEndElement:
                         unicodeTextLenSize = 2;
                         break;
                     case XmlBinaryNodeType.UnicodeChars32Text:
                     case XmlBinaryNodeType.UnicodeChars32TextWithEndElement:
                         unicodeTextLenSize = 4;
                         break;
                 }
                 int unicodeTextLength = ReadInt(unicodeTextLenSize);
                 if ((offset + unicodeTextLength) > xmlDoc.Length)
                 {
                     ThrowOffsetException("Error reading UnicodeCharsXText");
                 }
                 byte[] temp = new byte[unicodeTextLength];
                 Buffer.BlockCopy(xmlDoc, offset, temp, 0, unicodeTextLength);
                 newNode.Text = unicodeEncoding.GetString(temp, 0, temp.Length);
                 offset += unicodeTextLength;
             }
             break;
         case XmlBinaryNodeType.Bytes8Text:
         case XmlBinaryNodeType.Bytes8TextWithEndElement:
         case XmlBinaryNodeType.Bytes16Text:
         case XmlBinaryNodeType.Bytes16TextWithEndElement:
         case XmlBinaryNodeType.Bytes32Text:
         case XmlBinaryNodeType.Bytes32TextWithEndElement:
             {
                 int byteArrayLenSize = 0;
                 switch (nodeType)
                 {
                     case XmlBinaryNodeType.Bytes8Text:
                     case XmlBinaryNodeType.Bytes8TextWithEndElement:
                         byteArrayLenSize = 1;
                         break;
                     case XmlBinaryNodeType.Bytes16Text:
                     case XmlBinaryNodeType.Bytes16TextWithEndElement:
                         byteArrayLenSize = 2;
                         break;
                     case XmlBinaryNodeType.Bytes32Text:
                     case XmlBinaryNodeType.Bytes32TextWithEndElement:
                         byteArrayLenSize = 4;
                         break;
                 }
                 int byteArrayLength = ReadInt(byteArrayLenSize);
                 if ((offset + byteArrayLength) > xmlDoc.Length)
                 {
                     ThrowOffsetException("Error reading BytesXText");
                 }
                 newNode.Bytes = new byte[byteArrayLength];
                 Buffer.BlockCopy(xmlDoc, offset, newNode.Bytes, 0, byteArrayLength);
                 offset += byteArrayLength;
             }
             break;
         case XmlBinaryNodeType.Int8Text:
         case XmlBinaryNodeType.Int8TextWithEndElement:
             newNode.IntValue = ReadInt(1);
             break;
         case XmlBinaryNodeType.Int16Text:
         case XmlBinaryNodeType.Int16TextWithEndElement:
             newNode.IntValue = ReadInt(2);
             break;
         case XmlBinaryNodeType.Int32Text:
         case XmlBinaryNodeType.Int32TextWithEndElement:
             newNode.IntValue = ReadInt(4);
             break;
         case XmlBinaryNodeType.Int64Text:
         case XmlBinaryNodeType.Int64TextWithEndElement:
         case XmlBinaryNodeType.UInt64Text:
         case XmlBinaryNodeType.UInt64TextWithEndElement:
             newNode.LongValue = ReadLong();
             break;
         case XmlBinaryNodeType.FloatText:
         case XmlBinaryNodeType.FloatTextWithEndElement:
             newNode.FloatValue = ReadFloat();
             break;
         case XmlBinaryNodeType.DoubleText:
         case XmlBinaryNodeType.DoubleTextWithEndElement:
             newNode.DoubleValue = ReadDouble();
             break;
         case XmlBinaryNodeType.DecimalText:
         case XmlBinaryNodeType.DecimalTextWithEndElement:
             newNode.DecimalValue = ReadDecimal();
             break;
         case XmlBinaryNodeType.DateTimeText:
         case XmlBinaryNodeType.DateTimeTextWithEndElement:
             newNode.DateTimeValue = ReadDateTime();
             break;
         case XmlBinaryNodeType.TimeSpanText:
         case XmlBinaryNodeType.TimeSpanTextWithEndElement:
             newNode.TimeSpanValue = TimeSpan.FromTicks(ReadLong());
             break;
         case XmlBinaryNodeType.EmptyText:
         case XmlBinaryNodeType.EmptyTextWithEndElement:
             newNode.Text = "";
             break;
         case XmlBinaryNodeType.ZeroText:
         case XmlBinaryNodeType.ZeroTextWithEndElement:
             newNode.Text = "0";
             break;
         case XmlBinaryNodeType.OneText:
         case XmlBinaryNodeType.OneTextWithEndElement:
             newNode.Text = "1";
             break;
         case XmlBinaryNodeType.TrueText:
         case XmlBinaryNodeType.TrueTextWithEndElement:
             newNode.Text = "true";
             break;
         case XmlBinaryNodeType.FalseText:
         case XmlBinaryNodeType.FalseTextWithEndElement:
             newNode.Text = "false";
             break;
         case XmlBinaryNodeType.DictionaryText:
         case XmlBinaryNodeType.DictionaryTextWithEndElement:
             newNode.DictionaryText = ReadDictionaryString();
             break;
         case XmlBinaryNodeType.GuidText:
         case XmlBinaryNodeType.GuidTextWithEndElement:
             newNode.GuidValue = ReadGuid();
             break;
         case XmlBinaryNodeType.UniqueIdText:
         case XmlBinaryNodeType.UniqueIdTextWithEndElement:
             {
                 byte[] uniqueIdBytes = new byte[16];
                 if ((offset + uniqueIdBytes.Length) > xmlDoc.Length)
                 {
                     ThrowOffsetException("Error reading UniqueId");
                 }
                 Buffer.BlockCopy(xmlDoc, offset, uniqueIdBytes, 0, uniqueIdBytes.Length);
                 newNode.UniqueIdValue = new UniqueId(uniqueIdBytes);
                 offset += uniqueIdBytes.Length;
             }
             break;
         case XmlBinaryNodeType.StartListTextWithEndElement:
             throw new ArgumentException("StartListTextWithEndElement is an invalid node!");
         case XmlBinaryNodeType.StartListText:
             {
                 depth++;
                 ParseList(newNode);
                 depth--;
             }
             break;
         default:
             throw new ArgumentException(String.Format("Error, the test is not ready to handle the type {0:X2} ({1}) yet", nodeType, XmlBinaryNodeType.GetNodeName(nodeType)));
     }
 }
        private void Parse(ref XmlBinaryNode parent, bool insideAttribute, bool insideArray)
        {
            if (offset >= xmlDoc.Length)
            {
                return;
            }
            bool first = true;

            while (offset < xmlDoc.Length)
            {
                if (!first && insideAttribute)
                {
                    return;
                }
                first = false;
                byte nodeType = xmlDoc[offset];
                if (XmlBinaryNodeType.IsTextNode(nodeType) || XmlBinaryNodeType.IsTextNodeWithEndElement(nodeType))
                {
                    ParseContentNode(parent);
                    if (XmlBinaryNodeType.IsTextNodeWithEndElement(nodeType))
                    {
                        depth--;
                        return;
                    }
                }
                else
                {
                    offset++;
                    XmlBinaryNode newNode = new XmlBinaryNode(nodeType, depth);
                    if (parent == null)
                    {
                        parent = newNode;
                    }
                    else
                    {
                        parent.AddChild(newNode);
                    }
                    switch (nodeType)
                    {
                    case XmlBinaryNodeType.EndElement:
                        depth--;
                        return;

                    case XmlBinaryNodeType.Comment:
                        newNode.Text = ReadString(0);
                        break;

                    case XmlBinaryNodeType.ShortElement:
                    case XmlBinaryNodeType.ShortDictionaryElement:
                    case XmlBinaryNodeType.Element:
                    case XmlBinaryNodeType.DictionaryElement:
                    {
                        bool isDictionaryElement = XmlBinaryNodeType.IsDictionaryElementNode(nodeType);
                        bool isShortElement      = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                        if (!isShortElement)
                        {
                            newNode.Prefix = ReadString(0);
                        }
                        if (isDictionaryElement)
                        {
                            newNode.DictionaryLocalName = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.LocalName = ReadString(0);
                        }
                        int oldDepth = depth;
                        depth++;
                        Parse(ref newNode);
                        if (depth != oldDepth)
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                        if (insideArray)
                        {
                            return;
                        }
                    }
                    break;

                    case XmlBinaryNodeType.PrefixElementA:
                    case XmlBinaryNodeType.PrefixElementB:
                    case XmlBinaryNodeType.PrefixElementC:
                    case XmlBinaryNodeType.PrefixElementD:
                    case XmlBinaryNodeType.PrefixElementE:
                    case XmlBinaryNodeType.PrefixElementF:
                    case XmlBinaryNodeType.PrefixElementG:
                    case XmlBinaryNodeType.PrefixElementH:
                    case XmlBinaryNodeType.PrefixElementI:
                    case XmlBinaryNodeType.PrefixElementJ:
                    case XmlBinaryNodeType.PrefixElementK:
                    case XmlBinaryNodeType.PrefixElementL:
                    case XmlBinaryNodeType.PrefixElementM:
                    case XmlBinaryNodeType.PrefixElementN:
                    case XmlBinaryNodeType.PrefixElementO:
                    case XmlBinaryNodeType.PrefixElementP:
                    case XmlBinaryNodeType.PrefixElementQ:
                    case XmlBinaryNodeType.PrefixElementR:
                    case XmlBinaryNodeType.PrefixElementS:
                    case XmlBinaryNodeType.PrefixElementT:
                    case XmlBinaryNodeType.PrefixElementU:
                    case XmlBinaryNodeType.PrefixElementV:
                    case XmlBinaryNodeType.PrefixElementW:
                    case XmlBinaryNodeType.PrefixElementX:
                    case XmlBinaryNodeType.PrefixElementY:
                    case XmlBinaryNodeType.PrefixElementZ:
                    case XmlBinaryNodeType.PrefixDictionaryElementA:
                    case XmlBinaryNodeType.PrefixDictionaryElementB:
                    case XmlBinaryNodeType.PrefixDictionaryElementC:
                    case XmlBinaryNodeType.PrefixDictionaryElementD:
                    case XmlBinaryNodeType.PrefixDictionaryElementE:
                    case XmlBinaryNodeType.PrefixDictionaryElementF:
                    case XmlBinaryNodeType.PrefixDictionaryElementG:
                    case XmlBinaryNodeType.PrefixDictionaryElementH:
                    case XmlBinaryNodeType.PrefixDictionaryElementI:
                    case XmlBinaryNodeType.PrefixDictionaryElementJ:
                    case XmlBinaryNodeType.PrefixDictionaryElementK:
                    case XmlBinaryNodeType.PrefixDictionaryElementL:
                    case XmlBinaryNodeType.PrefixDictionaryElementM:
                    case XmlBinaryNodeType.PrefixDictionaryElementN:
                    case XmlBinaryNodeType.PrefixDictionaryElementO:
                    case XmlBinaryNodeType.PrefixDictionaryElementP:
                    case XmlBinaryNodeType.PrefixDictionaryElementQ:
                    case XmlBinaryNodeType.PrefixDictionaryElementR:
                    case XmlBinaryNodeType.PrefixDictionaryElementS:
                    case XmlBinaryNodeType.PrefixDictionaryElementT:
                    case XmlBinaryNodeType.PrefixDictionaryElementU:
                    case XmlBinaryNodeType.PrefixDictionaryElementV:
                    case XmlBinaryNodeType.PrefixDictionaryElementW:
                    case XmlBinaryNodeType.PrefixDictionaryElementX:
                    case XmlBinaryNodeType.PrefixDictionaryElementY:
                    case XmlBinaryNodeType.PrefixDictionaryElementZ:
                    {
                        char prefixLetter;
                        bool isDictionaryElement = XmlBinaryNodeType.IsDictionaryElementNode(nodeType);
                        prefixLetter   = (char)((int)'a' + (int)nodeType - (int)(isDictionaryElement ? XmlBinaryNodeType.PrefixDictionaryElementA : XmlBinaryNodeType.PrefixElementA));
                        newNode.Prefix = new string(prefixLetter, 1);
                        if (isDictionaryElement)
                        {
                            newNode.DictionaryLocalName = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.LocalName = ReadString(0);
                        }
                        int oldDepth = depth;
                        depth++;
                        Parse(ref newNode);
                        if (depth != oldDepth)
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                        if (insideArray)
                        {
                            return;
                        }
                    }
                    break;

                    case XmlBinaryNodeType.ShortAttribute:
                    case XmlBinaryNodeType.ShortDictionaryAttribute:
                    case XmlBinaryNodeType.Attribute:
                    case XmlBinaryNodeType.DictionaryAttribute:
                    {
                        bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                        bool isShortAttribute      = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                        if (!isShortAttribute)
                        {
                            newNode.Prefix = ReadString(0);
                        }
                        if (isDictionaryAttribute)
                        {
                            newNode.DictionaryLocalName = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.LocalName = ReadString(0);
                        }
                        int oldDepth = depth;
                        depth++;
                        Parse(ref newNode, true);
                        if (depth != (oldDepth + 1))
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                        depth--;
                        if (newNode.Children.Count != 1)
                        {
                            throw new ArgumentException("Error, attribute nodes must have exactly one child, at offset " + offset);
                        }
                    }
                    break;

                    case XmlBinaryNodeType.ShortXmlnsAttribute:
                    case XmlBinaryNodeType.ShortDictionaryXmlnsAttribute:
                    case XmlBinaryNodeType.XmlnsAttribute:
                    case XmlBinaryNodeType.DictionaryXmlnsAttribute:
                    {
                        bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                        bool isShortAttribute      = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                        if (!isShortAttribute)
                        {
                            newNode.Prefix = ReadString(0);
                        }
                        if (isDictionaryAttribute)
                        {
                            newNode.DictionaryNamespaceURI = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.NamespaceURI = ReadString(0);
                        }
                    }
                    break;

                    case XmlBinaryNodeType.PrefixAttributeA:
                    case XmlBinaryNodeType.PrefixAttributeB:
                    case XmlBinaryNodeType.PrefixAttributeC:
                    case XmlBinaryNodeType.PrefixAttributeD:
                    case XmlBinaryNodeType.PrefixAttributeE:
                    case XmlBinaryNodeType.PrefixAttributeF:
                    case XmlBinaryNodeType.PrefixAttributeG:
                    case XmlBinaryNodeType.PrefixAttributeH:
                    case XmlBinaryNodeType.PrefixAttributeI:
                    case XmlBinaryNodeType.PrefixAttributeJ:
                    case XmlBinaryNodeType.PrefixAttributeK:
                    case XmlBinaryNodeType.PrefixAttributeL:
                    case XmlBinaryNodeType.PrefixAttributeM:
                    case XmlBinaryNodeType.PrefixAttributeN:
                    case XmlBinaryNodeType.PrefixAttributeO:
                    case XmlBinaryNodeType.PrefixAttributeP:
                    case XmlBinaryNodeType.PrefixAttributeQ:
                    case XmlBinaryNodeType.PrefixAttributeR:
                    case XmlBinaryNodeType.PrefixAttributeS:
                    case XmlBinaryNodeType.PrefixAttributeT:
                    case XmlBinaryNodeType.PrefixAttributeU:
                    case XmlBinaryNodeType.PrefixAttributeV:
                    case XmlBinaryNodeType.PrefixAttributeW:
                    case XmlBinaryNodeType.PrefixAttributeX:
                    case XmlBinaryNodeType.PrefixAttributeY:
                    case XmlBinaryNodeType.PrefixAttributeZ:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeA:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeB:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeC:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeD:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeE:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeF:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeG:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeH:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeI:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeJ:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeK:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeL:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeM:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeN:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeO:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeP:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeQ:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeR:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeS:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeT:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeU:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeV:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeW:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeX:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeY:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeZ:
                    {
                        char prefixLetter;
                        bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                        prefixLetter   = (char)((int)'a' + (int)nodeType - (int)(isDictionaryAttribute ? XmlBinaryNodeType.PrefixDictionaryAttributeA : XmlBinaryNodeType.PrefixAttributeA));
                        newNode.Prefix = new string(prefixLetter, 1);
                        if (isDictionaryAttribute)
                        {
                            newNode.DictionaryLocalName = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.LocalName = ReadString(0);
                        }
                        int oldDepth = depth;
                        depth++;
                        Parse(ref newNode, true);
                        if (depth != (oldDepth + 1))
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                        depth--;
                        if (newNode.Children.Count != 1)
                        {
                            throw new ArgumentException("Error, attribute nodes must have exactly one child, at offset " + offset);
                        }
                    }
                    break;

                    case XmlBinaryNodeType.Array:
                    {
                        int oldDepth = depth;
                        depth++;
                        ParseArray(newNode);
                        if (depth != oldDepth)
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                    }
                    break;

                    default:
                        throw new ArgumentException(String.Format("Error, the test is not ready to handle the type {0:X2} ({1}) yet", nodeType, XmlBinaryNodeType.GetNodeName(nodeType)));
                    }
                }
            }
        }
        private void ParseContentNode(XmlBinaryNode parent)
        {
            byte nodeType = xmlDoc[offset];

            offset++;
            XmlBinaryNode newNode = new XmlBinaryNode(nodeType, depth);

            parent.AddChild(newNode);
            switch (nodeType)
            {
            case XmlBinaryNodeType.Chars8Text:
            case XmlBinaryNodeType.Chars8TextWithEndElement:
                newNode.Text = ReadString(8);
                break;

            case XmlBinaryNodeType.Chars16Text:
            case XmlBinaryNodeType.Chars16TextWithEndElement:
                newNode.Text = ReadString(16);
                break;

            case XmlBinaryNodeType.Chars32Text:
            case XmlBinaryNodeType.Chars32TextWithEndElement:
                newNode.Text = ReadString(32);
                break;

            case XmlBinaryNodeType.UnicodeChars8Text:
            case XmlBinaryNodeType.UnicodeChars8TextWithEndElement:
            case XmlBinaryNodeType.UnicodeChars16Text:
            case XmlBinaryNodeType.UnicodeChars16TextWithEndElement:
            case XmlBinaryNodeType.UnicodeChars32Text:
            case XmlBinaryNodeType.UnicodeChars32TextWithEndElement:
            {
                int unicodeTextLenSize = 0;
                switch (nodeType)
                {
                case XmlBinaryNodeType.UnicodeChars8Text:
                case XmlBinaryNodeType.UnicodeChars8TextWithEndElement:
                    unicodeTextLenSize = 1;
                    break;

                case XmlBinaryNodeType.UnicodeChars16Text:
                case XmlBinaryNodeType.UnicodeChars16TextWithEndElement:
                    unicodeTextLenSize = 2;
                    break;

                case XmlBinaryNodeType.UnicodeChars32Text:
                case XmlBinaryNodeType.UnicodeChars32TextWithEndElement:
                    unicodeTextLenSize = 4;
                    break;
                }
                int unicodeTextLength = ReadInt(unicodeTextLenSize);
                if ((offset + unicodeTextLength) > xmlDoc.Length)
                {
                    ThrowOffsetException("Error reading UnicodeCharsXText");
                }
                byte[] temp = new byte[unicodeTextLength];
                Buffer.BlockCopy(xmlDoc, offset, temp, 0, unicodeTextLength);
                newNode.Text = unicodeEncoding.GetString(temp, 0, temp.Length);
                offset      += unicodeTextLength;
            }
            break;

            case XmlBinaryNodeType.Bytes8Text:
            case XmlBinaryNodeType.Bytes8TextWithEndElement:
            case XmlBinaryNodeType.Bytes16Text:
            case XmlBinaryNodeType.Bytes16TextWithEndElement:
            case XmlBinaryNodeType.Bytes32Text:
            case XmlBinaryNodeType.Bytes32TextWithEndElement:
            {
                int byteArrayLenSize = 0;
                switch (nodeType)
                {
                case XmlBinaryNodeType.Bytes8Text:
                case XmlBinaryNodeType.Bytes8TextWithEndElement:
                    byteArrayLenSize = 1;
                    break;

                case XmlBinaryNodeType.Bytes16Text:
                case XmlBinaryNodeType.Bytes16TextWithEndElement:
                    byteArrayLenSize = 2;
                    break;

                case XmlBinaryNodeType.Bytes32Text:
                case XmlBinaryNodeType.Bytes32TextWithEndElement:
                    byteArrayLenSize = 4;
                    break;
                }
                int byteArrayLength = ReadInt(byteArrayLenSize);
                if ((offset + byteArrayLength) > xmlDoc.Length)
                {
                    ThrowOffsetException("Error reading BytesXText");
                }
                newNode.Bytes = new byte[byteArrayLength];
                Buffer.BlockCopy(xmlDoc, offset, newNode.Bytes, 0, byteArrayLength);
                offset += byteArrayLength;
            }
            break;

            case XmlBinaryNodeType.Int8Text:
            case XmlBinaryNodeType.Int8TextWithEndElement:
                newNode.IntValue = ReadInt(1);
                break;

            case XmlBinaryNodeType.Int16Text:
            case XmlBinaryNodeType.Int16TextWithEndElement:
                newNode.IntValue = ReadInt(2);
                break;

            case XmlBinaryNodeType.Int32Text:
            case XmlBinaryNodeType.Int32TextWithEndElement:
                newNode.IntValue = ReadInt(4);
                break;

            case XmlBinaryNodeType.Int64Text:
            case XmlBinaryNodeType.Int64TextWithEndElement:
            case XmlBinaryNodeType.UInt64Text:
            case XmlBinaryNodeType.UInt64TextWithEndElement:
                newNode.LongValue = ReadLong();
                break;

            case XmlBinaryNodeType.FloatText:
            case XmlBinaryNodeType.FloatTextWithEndElement:
                newNode.FloatValue = ReadFloat();
                break;

            case XmlBinaryNodeType.DoubleText:
            case XmlBinaryNodeType.DoubleTextWithEndElement:
                newNode.DoubleValue = ReadDouble();
                break;

            case XmlBinaryNodeType.DecimalText:
            case XmlBinaryNodeType.DecimalTextWithEndElement:
                newNode.DecimalValue = ReadDecimal();
                break;

            case XmlBinaryNodeType.DateTimeText:
            case XmlBinaryNodeType.DateTimeTextWithEndElement:
                newNode.DateTimeValue = ReadDateTime();
                break;

            case XmlBinaryNodeType.TimeSpanText:
            case XmlBinaryNodeType.TimeSpanTextWithEndElement:
                newNode.TimeSpanValue = TimeSpan.FromTicks(ReadLong());
                break;

            case XmlBinaryNodeType.EmptyText:
            case XmlBinaryNodeType.EmptyTextWithEndElement:
                newNode.Text = "";
                break;

            case XmlBinaryNodeType.ZeroText:
            case XmlBinaryNodeType.ZeroTextWithEndElement:
                newNode.Text = "0";
                break;

            case XmlBinaryNodeType.OneText:
            case XmlBinaryNodeType.OneTextWithEndElement:
                newNode.Text = "1";
                break;

            case XmlBinaryNodeType.TrueText:
            case XmlBinaryNodeType.TrueTextWithEndElement:
                newNode.Text = "true";
                break;

            case XmlBinaryNodeType.FalseText:
            case XmlBinaryNodeType.FalseTextWithEndElement:
                newNode.Text = "false";
                break;

            case XmlBinaryNodeType.DictionaryText:
            case XmlBinaryNodeType.DictionaryTextWithEndElement:
                newNode.DictionaryText = ReadDictionaryString();
                break;

            case XmlBinaryNodeType.GuidText:
            case XmlBinaryNodeType.GuidTextWithEndElement:
                newNode.GuidValue = ReadGuid();
                break;

            case XmlBinaryNodeType.UniqueIdText:
            case XmlBinaryNodeType.UniqueIdTextWithEndElement:
            {
                byte[] uniqueIdBytes = new byte[16];
                if ((offset + uniqueIdBytes.Length) > xmlDoc.Length)
                {
                    ThrowOffsetException("Error reading UniqueId");
                }
                Buffer.BlockCopy(xmlDoc, offset, uniqueIdBytes, 0, uniqueIdBytes.Length);
                newNode.UniqueIdValue = new UniqueId(uniqueIdBytes);
                offset += uniqueIdBytes.Length;
            }
            break;

            case XmlBinaryNodeType.StartListTextWithEndElement:
                throw new ArgumentException("StartListTextWithEndElement is an invalid node!");

            case XmlBinaryNodeType.StartListText:
            {
                depth++;
                ParseList(newNode);
                depth--;
            }
            break;

            default:
                throw new ArgumentException(String.Format("Error, the test is not ready to handle the type {0:X2} ({1}) yet", nodeType, XmlBinaryNodeType.GetNodeName(nodeType)));
            }
        }