1 //------------------------------------------------------------ 2 // Copyright (c) Microsoft Corporation. All rights reserved. 3 //------------------------------------------------------------ 4 namespace System.Xml 5 { 6 // Element => StartElement Attribute* Content EndElement 7 // | StartElement Attribute* Text // Text must be WithEndElement 8 // | Array StartElement Attribute* EndElement type MB32(Count) byte[Count * sizeof(type)] 9 10 // StartElement => ShortElementNode Name(LocalName) 11 // | ElementNode Name(Prefix) Name(LocalName) 12 // | ShortDictionaryElementNode MB32(LocalName) 13 // | PrefixDictionaryElement[A-Z]Node MB32(LocalName) 14 // | DictionaryElementNode Name(Prefix) MB32(LocalName) 15 // | PrefixElement[A-Z]Node Name(LocalName) 16 17 // EndElement => EndElementNode 18 // Content => (Element | ArrayElement | Text | Comment)* 19 20 // Attribute => ShortAttributeNode Name(LocalName) Text 21 // | AttributeNode Name(Prefix) Name(LocalName) Text 22 // | ShortDictionaryAttributeNode MB32(LocalName) Text 23 // | DictionaryAttributeNode Name(Prefix) MB32(LocalName) Text 24 // | ShortXmlnsAttributeNode Name(Namespace) 25 // | XmlnsAttributeNode Name(Prefix) Name(Namespace) 26 // | ShortDictionaryXmlnsAttributeNode MB32(Namespace) 27 // | DictionaryXmlnsAttributeNode Name(Prefix) MB32(Namespace) 28 // | PrefixAttribute[A-Z] Name(LocalName) Text 29 // | PrefixDictionaryAttribute[A-Z] MB32(LocalName) Text 30 31 // Text => BinaryTextNode 32 // | CharsTextNode 33 // | EmptyTextNode 34 // | DictionaryTextNode MB32(Id) 35 // | ZeroTextNode 36 // | OneTextNode 37 // | TrueTextNode 38 // | FalseTextNode 39 // | Int8TextNode Int8 40 // | Int16TextNode Int16 41 // | Int32TextNode Int32 42 // | Int64TextNode Int64 43 // | FloatTextNode Float 44 // | DoubleTextNode Double 45 // | DecimalTextNode Decimal 46 // | DateTimeTextNode DateTime 47 // | StartListNode Text* EndListNode // Restriction: Cannot nest ListNode 48 // | UniqueIdTextNode byte[16] // byte[16] is a Guid (from Guid.ToBinary()) (urn:uuid:xxxx-xxxx-xxx) 49 // | GuidTextNode byte[16] // byte[16] is a Guid (from Guid.ToBinary()) (xxxx-xxxx-xxx) 50 // | TimeSpanNode Int64 51 // | UInt64TextNode UInt64 52 // | BoolTextNode Int8 53 // BinaryText => Bytes8TextNode UInt8 byte* 54 // | Bytes16TextNode UInt16 byte* 55 // | Bytes32TextNode UInt31 byte* 56 // CharsText => Chars8TextNode UInt8 byte* // UTF8Chars 57 // | Chars16TextNode UInt16 byte* 58 // | Chars32TextNode Unt31 byte* 59 // | UnicodeChars8TextNode UInt8 char* 60 // | UnicodeChars16TextNode UInt16 char* 61 // | UnicodeChars32TextNode UInt31 char* 62 // | QNameDictionaryTextNode UInt8 MB32(LocalName) // UInt8 0-25 => 'a'-'z' 63 // Comment => CommentNode Name(Text) 64 // Name => MB32 byte* // Length, UTF8Chars 65 // MB32(x:x>=0x80) => byte(0x80 | (x & 0x7F)) MB32(x >> 7) 66 // MB32(x:x<0x80) => byte(x) 67 68 69 // In order to help differentiate text from binary (where someone mixes up format and implementation) we overlay binary 70 // nodes that are illegal to start a document with text characters that are legal to start a document. Specifically these values are: 71 // ' ' = 32 72 // '\t' = 9 73 // '\n' = 10 74 // '\r' = 13 75 // '<' = 60 76 // The attribute nodes (MinAttribute to MaxAttribute) overlay all of these values and are invalid as the first byte of the document 77 78 enum XmlBinaryNodeType 79 { 80 // ProcessingInstruction = 0, // Reserved (Not supported) 81 EndElement = 1, 82 Comment = 2, 83 Array = 3, 84 85 MinAttribute = Array + 1, 86 ShortAttribute = MinAttribute + 0, 87 Attribute = MinAttribute + 1, 88 ShortDictionaryAttribute = MinAttribute + 2, 89 DictionaryAttribute = MinAttribute + 3, 90 ShortXmlnsAttribute = MinAttribute + 4, 91 XmlnsAttribute = MinAttribute + 5, 92 ShortDictionaryXmlnsAttribute = MinAttribute + 6, 93 DictionaryXmlnsAttribute = MinAttribute + 7, 94 PrefixDictionaryAttributeA = MinAttribute + 8, 95 PrefixDictionaryAttributeB = PrefixDictionaryAttributeA + 1, 96 PrefixDictionaryAttributeC = PrefixDictionaryAttributeB + 1, 97 PrefixDictionaryAttributeD = PrefixDictionaryAttributeC + 1, 98 PrefixDictionaryAttributeE = PrefixDictionaryAttributeD + 1, 99 PrefixDictionaryAttributeF = PrefixDictionaryAttributeE + 1, 100 PrefixDictionaryAttributeG = PrefixDictionaryAttributeF + 1, 101 PrefixDictionaryAttributeH = PrefixDictionaryAttributeG + 1, 102 PrefixDictionaryAttributeI = PrefixDictionaryAttributeH + 1, 103 PrefixDictionaryAttributeJ = PrefixDictionaryAttributeI + 1, 104 PrefixDictionaryAttributeK = PrefixDictionaryAttributeJ + 1, 105 PrefixDictionaryAttributeL = PrefixDictionaryAttributeK + 1, 106 PrefixDictionaryAttributeM = PrefixDictionaryAttributeL + 1, 107 PrefixDictionaryAttributeN = PrefixDictionaryAttributeM + 1, 108 PrefixDictionaryAttributeO = PrefixDictionaryAttributeN + 1, 109 PrefixDictionaryAttributeP = PrefixDictionaryAttributeO + 1, 110 PrefixDictionaryAttributeQ = PrefixDictionaryAttributeP + 1, 111 PrefixDictionaryAttributeR = PrefixDictionaryAttributeQ + 1, 112 PrefixDictionaryAttributeS = PrefixDictionaryAttributeR + 1, 113 PrefixDictionaryAttributeT = PrefixDictionaryAttributeS + 1, 114 PrefixDictionaryAttributeU = PrefixDictionaryAttributeT + 1, 115 PrefixDictionaryAttributeV = PrefixDictionaryAttributeU + 1, 116 PrefixDictionaryAttributeW = PrefixDictionaryAttributeV + 1, 117 PrefixDictionaryAttributeX = PrefixDictionaryAttributeW + 1, 118 PrefixDictionaryAttributeY = PrefixDictionaryAttributeX + 1, 119 PrefixDictionaryAttributeZ = PrefixDictionaryAttributeY + 1, 120 PrefixAttributeA = PrefixDictionaryAttributeZ + 1, 121 PrefixAttributeB = PrefixAttributeA + 1, 122 PrefixAttributeC = PrefixAttributeB + 1, 123 PrefixAttributeD = PrefixAttributeC + 1, 124 PrefixAttributeE = PrefixAttributeD + 1, 125 PrefixAttributeF = PrefixAttributeE + 1, 126 PrefixAttributeG = PrefixAttributeF + 1, 127 PrefixAttributeH = PrefixAttributeG + 1, 128 PrefixAttributeI = PrefixAttributeH + 1, 129 PrefixAttributeJ = PrefixAttributeI + 1, 130 PrefixAttributeK = PrefixAttributeJ + 1, 131 PrefixAttributeL = PrefixAttributeK + 1, 132 PrefixAttributeM = PrefixAttributeL + 1, 133 PrefixAttributeN = PrefixAttributeM + 1, 134 PrefixAttributeO = PrefixAttributeN + 1, 135 PrefixAttributeP = PrefixAttributeO + 1, 136 PrefixAttributeQ = PrefixAttributeP + 1, 137 PrefixAttributeR = PrefixAttributeQ + 1, 138 PrefixAttributeS = PrefixAttributeR + 1, 139 PrefixAttributeT = PrefixAttributeS + 1, 140 PrefixAttributeU = PrefixAttributeT + 1, 141 PrefixAttributeV = PrefixAttributeU + 1, 142 PrefixAttributeW = PrefixAttributeV + 1, 143 PrefixAttributeX = PrefixAttributeW + 1, 144 PrefixAttributeY = PrefixAttributeX + 1, 145 PrefixAttributeZ = PrefixAttributeY + 1, 146 MaxAttribute = PrefixAttributeZ, 147 148 MinElement = MaxAttribute + 1, 149 ShortElement = MinElement, 150 Element = MinElement + 1, 151 ShortDictionaryElement = MinElement + 2, 152 DictionaryElement = MinElement + 3, 153 PrefixDictionaryElementA = MinElement + 4, 154 PrefixDictionaryElementB = PrefixDictionaryElementA + 1, 155 PrefixDictionaryElementC = PrefixDictionaryElementB + 1, 156 PrefixDictionaryElementD = PrefixDictionaryElementC + 1, 157 PrefixDictionaryElementE = PrefixDictionaryElementD + 1, 158 PrefixDictionaryElementF = PrefixDictionaryElementE + 1, 159 PrefixDictionaryElementG = PrefixDictionaryElementF + 1, 160 PrefixDictionaryElementH = PrefixDictionaryElementG + 1, 161 PrefixDictionaryElementI = PrefixDictionaryElementH + 1, 162 PrefixDictionaryElementJ = PrefixDictionaryElementI + 1, 163 PrefixDictionaryElementK = PrefixDictionaryElementJ + 1, 164 PrefixDictionaryElementL = PrefixDictionaryElementK + 1, 165 PrefixDictionaryElementM = PrefixDictionaryElementL + 1, 166 PrefixDictionaryElementN = PrefixDictionaryElementM + 1, 167 PrefixDictionaryElementO = PrefixDictionaryElementN + 1, 168 PrefixDictionaryElementP = PrefixDictionaryElementO + 1, 169 PrefixDictionaryElementQ = PrefixDictionaryElementP + 1, 170 PrefixDictionaryElementR = PrefixDictionaryElementQ + 1, 171 PrefixDictionaryElementS = PrefixDictionaryElementR + 1, 172 PrefixDictionaryElementT = PrefixDictionaryElementS + 1, 173 PrefixDictionaryElementU = PrefixDictionaryElementT + 1, 174 PrefixDictionaryElementV = PrefixDictionaryElementU + 1, 175 PrefixDictionaryElementW = PrefixDictionaryElementV + 1, 176 PrefixDictionaryElementX = PrefixDictionaryElementW + 1, 177 PrefixDictionaryElementY = PrefixDictionaryElementX + 1, 178 PrefixDictionaryElementZ = PrefixDictionaryElementY + 1, 179 PrefixElementA = PrefixDictionaryElementZ + 1, 180 PrefixElementB = PrefixElementA + 1, 181 PrefixElementC = PrefixElementB + 1, 182 PrefixElementD = PrefixElementC + 1, 183 PrefixElementE = PrefixElementD + 1, 184 PrefixElementF = PrefixElementE + 1, 185 PrefixElementG = PrefixElementF + 1, 186 PrefixElementH = PrefixElementG + 1, 187 PrefixElementI = PrefixElementH + 1, 188 PrefixElementJ = PrefixElementI + 1, 189 PrefixElementK = PrefixElementJ + 1, 190 PrefixElementL = PrefixElementK + 1, 191 PrefixElementM = PrefixElementL + 1, 192 PrefixElementN = PrefixElementM + 1, 193 PrefixElementO = PrefixElementN + 1, 194 PrefixElementP = PrefixElementO + 1, 195 PrefixElementQ = PrefixElementP + 1, 196 PrefixElementR = PrefixElementQ + 1, 197 PrefixElementS = PrefixElementR + 1, 198 PrefixElementT = PrefixElementS + 1, 199 PrefixElementU = PrefixElementT + 1, 200 PrefixElementV = PrefixElementU + 1, 201 PrefixElementW = PrefixElementV + 1, 202 PrefixElementX = PrefixElementW + 1, 203 PrefixElementY = PrefixElementX + 1, 204 PrefixElementZ = PrefixElementY + 1, 205 MaxElement = PrefixElementZ, 206 207 // MinorVersion = MaxElement + 1, // Reserved (Not supported) 208 209 MinText = 0x80, // Must be even 210 ZeroText = MinText, 211 OneText = MinText + 1 * 2, 212 FalseText = MinText + 2 * 2, 213 TrueText = MinText + 3 * 2, 214 Int8Text = MinText + 4 * 2, 215 Int16Text = MinText + 5 * 2, 216 Int32Text = MinText + 6 * 2, 217 Int64Text = MinText + 7 * 2, 218 FloatText = MinText + 8 * 2, 219 DoubleText = MinText + 9 * 2, 220 DecimalText = MinText + 10 * 2, 221 DateTimeText = MinText + 11 * 2, 222 Chars8Text = MinText + 12 * 2, 223 Chars16Text = MinText + 13 * 2, 224 Chars32Text = MinText + 14 * 2, 225 Bytes8Text = MinText + 15 * 2, 226 Bytes16Text = MinText + 16 * 2, 227 Bytes32Text = MinText + 17 * 2, 228 StartListText = MinText + 18 * 2, 229 EndListText = MinText + 19 * 2, 230 EmptyText = MinText + 20 * 2, 231 DictionaryText = MinText + 21 * 2, 232 UniqueIdText = MinText + 22 * 2, 233 TimeSpanText = MinText + 23 * 2, 234 GuidText = MinText + 24 * 2, 235 UInt64Text = MinText + 25 * 2, 236 BoolText = MinText + 26 * 2, 237 UnicodeChars8Text = MinText + 27 * 2, 238 UnicodeChars16Text = MinText + 28 * 2, 239 UnicodeChars32Text = MinText + 29 * 2, 240 QNameDictionaryText = MinText + 30 * 2, 241 242 ZeroTextWithEndElement = ZeroText + 1, 243 OneTextWithEndElement = OneText + 1, 244 FalseTextWithEndElement = FalseText + 1, 245 TrueTextWithEndElement = TrueText + 1, 246 Int8TextWithEndElement = Int8Text + 1, 247 Int16TextWithEndElement = Int16Text + 1, 248 Int32TextWithEndElement = Int32Text + 1, 249 Int64TextWithEndElement = Int64Text + 1, 250 FloatTextWithEndElement = FloatText + 1, 251 DoubleTextWithEndElement = DoubleText + 1, 252 DecimalTextWithEndElement = DecimalText + 1, 253 DateTimeTextWithEndElement = DateTimeText + 1, 254 Chars8TextWithEndElement = Chars8Text + 1, 255 Chars16TextWithEndElement = Chars16Text + 1, 256 Chars32TextWithEndElement = Chars32Text + 1, 257 Bytes8TextWithEndElement = Bytes8Text + 1, 258 Bytes16TextWithEndElement = Bytes16Text + 1, 259 Bytes32TextWithEndElement = Bytes32Text + 1, 260 StartListTextWithEndElement = StartListText + 1, 261 EndListTextWithEndElement = EndListText + 1, 262 EmptyTextWithEndElement = EmptyText + 1, 263 DictionaryTextWithEndElement = DictionaryText + 1, 264 UniqueIdTextWithEndElement = UniqueIdText + 1, 265 TimeSpanTextWithEndElement = TimeSpanText + 1, 266 GuidTextWithEndElement = GuidText + 1, 267 UInt64TextWithEndElement = UInt64Text + 1, 268 BoolTextWithEndElement = BoolText + 1, 269 UnicodeChars8TextWithEndElement = UnicodeChars8Text + 1, 270 UnicodeChars16TextWithEndElement = UnicodeChars16Text + 1, 271 UnicodeChars32TextWithEndElement = UnicodeChars32Text + 1, 272 QNameDictionaryTextWithEndElement = QNameDictionaryText + 1, 273 MaxText = QNameDictionaryTextWithEndElement 274 } 275 } 276