Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DocumentXmlWriter.cs
Go to the documentation of this file.
2
3namespace System.Xml;
4
6{
7 private enum State
8 {
9 Error,
11 Prolog,
13 Content,
14 Last
15 }
16
37
38 private readonly DocumentXmlWriterType _type;
39
40 private readonly XmlNode _start;
41
42 private readonly XmlDocument _document;
43
45
46 private State _state;
47
48 private XmlNode _write;
49
50 private readonly List<XmlNode> _fragment;
51
52 private readonly XmlWriterSettings _settings;
53
55
56 private XmlNode _end;
57
58 private static readonly State[] s_changeState = new State[85]
59 {
60 State.Error,
61 State.Error,
62 State.Prolog,
63 State.Content,
64 State.Error,
65 State.Error,
66 State.Error,
67 State.Error,
68 State.Error,
69 State.Error,
70 State.Error,
71 State.Error,
72 State.Error,
73 State.Error,
74 State.Error,
75 State.Error,
76 State.Error,
77 State.Prolog,
78 State.Error,
79 State.Error,
80 State.Error,
81 State.Error,
82 State.Content,
83 State.Content,
84 State.Content,
85 State.Error,
86 State.Error,
87 State.Error,
88 State.Error,
89 State.Content,
90 State.Error,
91 State.Error,
92 State.Error,
93 State.Error,
94 State.Content,
95 State.Error,
96 State.Content,
97 State.Error,
98 State.Error,
99 State.Content,
100 State.Error,
101 State.Error,
102 State.Error,
103 State.Error,
104 State.Content,
105 State.Error,
106 State.Content,
107 State.Error,
108 State.Error,
109 State.Content,
110 State.Error,
111 State.Error,
112 State.Error,
113 State.Error,
114 State.Content,
115 State.Error,
116 State.Error,
117 State.Error,
118 State.Content,
119 State.Content,
120 State.Error,
121 State.Error,
122 State.Prolog,
123 State.Content,
124 State.Content,
125 State.Error,
126 State.Error,
127 State.Prolog,
128 State.Content,
129 State.Content,
130 State.Error,
131 State.Error,
132 State.Error,
133 State.Content,
134 State.Content,
135 State.Error,
136 State.Error,
137 State.Prolog,
138 State.Content,
139 State.Content,
140 State.Error,
141 State.Error,
142 State.Error,
143 State.Content,
145 };
146
148 {
149 set
150 {
152 }
153 }
154
156
158 {
159 set
160 {
162 }
163 }
164
166 {
167 set
168 {
169 _end = value;
170 }
171 }
172
173 internal override bool SupportsNamespaceDeclarationInChunks => true;
174
189
191 {
192 VerifyState(Method.WriteXmlDeclaration);
193 if (standalone != 0)
194 {
195 XmlNode node = _document.CreateXmlDeclaration("1.0", string.Empty, (standalone == XmlStandalone.Yes) ? "yes" : "no");
197 }
198 }
199
200 internal override void WriteXmlDeclaration(string xmldecl)
201 {
202 VerifyState(Method.WriteXmlDeclaration);
206 }
207
208 public override void WriteStartDocument()
209 {
210 VerifyState(Method.WriteStartDocument);
211 }
212
213 public override void WriteStartDocument(bool standalone)
214 {
215 VerifyState(Method.WriteStartDocument);
216 }
217
218 public override void WriteEndDocument()
219 {
220 VerifyState(Method.WriteEndDocument);
221 }
222
223 public override void WriteDocType(string name, string pubid, string sysid, string subset)
224 {
225 VerifyState(Method.WriteDocType);
228 }
229
230 public override void WriteStartElement(string prefix, string localName, string ns)
231 {
232 VerifyState(Method.WriteStartElement);
233 XmlNode xmlNode = _document.CreateElement(prefix, localName, ns);
235 _write = xmlNode;
236 }
237
238 public override void WriteEndElement()
239 {
240 VerifyState(Method.WriteEndElement);
241 if (_write == null)
242 {
243 throw new InvalidOperationException();
244 }
246 }
247
248 internal override void WriteEndElement(string prefix, string localName, string ns)
249 {
251 }
252
253 public override void WriteFullEndElement()
254 {
255 VerifyState(Method.WriteFullEndElement);
257 {
258 throw new InvalidOperationException();
259 }
260 xmlElement.IsEmpty = false;
261 _write = xmlElement.ParentNode;
262 }
263
264 internal override void WriteFullEndElement(string prefix, string localName, string ns)
265 {
267 }
268
269 internal override void StartElementContent()
270 {
271 }
272
273 public override void WriteStartAttribute(string prefix, string localName, string ns)
274 {
275 VerifyState(Method.WriteStartAttribute);
279 }
280
281 public override void WriteEndAttribute()
282 {
283 VerifyState(Method.WriteEndAttribute);
285 {
286 throw new InvalidOperationException();
287 }
288 if (!xmlAttribute.HasChildNodes)
289 {
292 }
293 _write = xmlAttribute.OwnerElement;
294 }
295
296 internal override void WriteNamespaceDeclaration(string prefix, string ns)
297 {
299 WriteString(ns);
301 }
302
310
311 internal override void WriteEndNamespaceDeclaration()
312 {
313 VerifyState(Method.WriteEndNamespaceDeclaration);
315 {
316 throw new InvalidOperationException();
317 }
318 if (!xmlAttribute.HasChildNodes)
319 {
322 }
323 _write = xmlAttribute.OwnerElement;
324 }
325
326 public override void WriteCData(string text)
327 {
328 VerifyState(Method.WriteCData);
329 XmlConvert.VerifyCharData(text, ExceptionType.ArgumentException);
332 }
333
334 public override void WriteComment(string text)
335 {
336 VerifyState(Method.WriteComment);
337 XmlConvert.VerifyCharData(text, ExceptionType.ArgumentException);
340 }
341
342 public override void WriteProcessingInstruction(string name, string text)
343 {
344 VerifyState(Method.WriteProcessingInstruction);
345 XmlConvert.VerifyCharData(text, ExceptionType.ArgumentException);
348 }
349
350 public override void WriteEntityRef(string name)
351 {
352 VerifyState(Method.WriteEntityRef);
355 }
356
357 public override void WriteCharEntity(char ch)
358 {
359 WriteString(char.ToString(ch));
360 }
361
362 public override void WriteWhitespace(string text)
363 {
364 VerifyState(Method.WriteWhitespace);
365 XmlConvert.VerifyCharData(text, ExceptionType.ArgumentException);
367 {
370 }
371 }
372
373 public override void WriteString(string text)
374 {
375 VerifyState(Method.WriteString);
376 XmlConvert.VerifyCharData(text, ExceptionType.ArgumentException);
379 }
380
381 public override void WriteSurrogateCharEntity(char lowCh, char highCh)
382 {
383 Span<char> span = stackalloc char[2] { highCh, lowCh };
385 WriteString(new string(value));
386 }
387
388 public override void WriteChars(char[] buffer, int index, int count)
389 {
390 WriteString(new string(buffer, index, count));
391 }
392
393 public override void WriteRaw(char[] buffer, int index, int count)
394 {
395 WriteString(new string(buffer, index, count));
396 }
397
398 public override void WriteRaw(string data)
399 {
400 WriteString(data);
401 }
402
403 public override void Close()
404 {
405 }
406
407 internal override void Close(WriteState currentState)
408 {
409 if (currentState == WriteState.Error)
410 {
411 return;
412 }
413 try
414 {
415 switch (_type)
416 {
417 case DocumentXmlWriterType.InsertSiblingAfter:
418 {
419 XmlNode parentNode = _start.ParentNode;
420 if (parentNode == null)
421 {
423 }
424 for (int num2 = _fragment.Count - 1; num2 >= 0; num2--)
425 {
426 parentNode.InsertAfter(_fragment[num2], _start);
427 }
428 break;
429 }
430 case DocumentXmlWriterType.InsertSiblingBefore:
431 {
432 XmlNode parentNode = _start.ParentNode;
433 if (parentNode == null)
434 {
436 }
437 for (int j = 0; j < _fragment.Count; j++)
438 {
439 parentNode.InsertBefore(_fragment[j], _start);
440 }
441 break;
442 }
443 case DocumentXmlWriterType.PrependChild:
444 {
445 for (int num = _fragment.Count - 1; num >= 0; num--)
446 {
448 }
449 break;
450 }
451 case DocumentXmlWriterType.AppendChild:
452 {
453 for (int i = 0; i < _fragment.Count; i++)
454 {
456 }
457 break;
458 }
459 case DocumentXmlWriterType.AppendAttribute:
461 break;
462 case DocumentXmlWriterType.ReplaceToFollowingSibling:
463 if (_fragment.Count == 0)
464 {
466 }
468 break;
469 }
470 }
471 finally
472 {
474 }
475 }
476
478 {
480 XmlAttributeCollection attributes = xmlElement.Attributes;
481 for (int i = 0; i < _fragment.Count; i++)
482 {
484 int num = attributes.FindNodeOffsetNS(xmlAttribute);
485 if (num != -1 && ((XmlAttribute)attributes.nodes[num]).Specified)
486 {
487 throw new XmlException(System.SR.Xml_DupAttributeName, (xmlAttribute.Prefix.Length == 0) ? xmlAttribute.LocalName : (xmlAttribute.Prefix + ":" + xmlAttribute.LocalName));
488 }
489 }
490 for (int j = 0; j < _fragment.Count; j++)
491 {
493 attributes.Append(node);
494 }
495 }
496
498 {
499 XmlNode parentNode = _start.ParentNode;
500 if (parentNode == null)
501 {
503 }
504 if (_start != _end)
505 {
507 {
509 }
510 if (_start.IsReadOnly)
511 {
513 }
515 }
517 parentNode.ReplaceChild(xmlNode, _start);
518 for (int num = _fragment.Count - 1; num >= 1; num--)
519 {
520 parentNode.InsertAfter(_fragment[num], xmlNode);
521 }
523 }
524
525 public override void Flush()
526 {
527 }
528
533
538
543
544 private void AddAttribute(XmlAttribute attr, XmlNode parent)
545 {
546 if (parent == null)
547 {
549 return;
550 }
551 if (!(parent is XmlElement xmlElement))
552 {
553 throw new InvalidOperationException();
554 }
555 xmlElement.Attributes.Append(attr);
556 }
557
558 private void AddChild(XmlNode node, XmlNode parent)
559 {
560 if (parent == null)
561 {
563 }
564 else
565 {
566 parent.AppendChild(node);
567 }
568 }
569
571 {
573 switch (_type)
574 {
575 case DocumentXmlWriterType.InsertSiblingAfter:
576 case DocumentXmlWriterType.InsertSiblingBefore:
577 {
578 XmlNode parentNode = _start.ParentNode;
579 if (parentNode != null)
580 {
581 xmlNodeType = parentNode.NodeType;
582 }
583 switch (xmlNodeType)
584 {
585 case XmlNodeType.Document:
586 return State.Prolog;
587 case XmlNodeType.DocumentFragment:
588 return State.Fragment;
589 }
590 break;
591 }
592 case DocumentXmlWriterType.PrependChild:
593 case DocumentXmlWriterType.AppendChild:
594 switch (_start.NodeType)
595 {
596 case XmlNodeType.Document:
597 return State.Prolog;
598 case XmlNodeType.DocumentFragment:
599 return State.Fragment;
600 }
601 break;
602 case DocumentXmlWriterType.AppendAttribute:
603 return State.Attribute;
604 }
605 return State.Content;
606 }
607
609 {
610 _state = s_changeState[(int)((int)method * 5 + _state)];
611 if (_state == State.Error)
612 {
614 }
615 }
616}
void Add(TKey key, TValue value)
static string Xml_ClosedOrError
Definition SR.cs:300
static string Xpn_NoContent
Definition SR.cs:1320
static string Xpn_MissingParent
Definition SR.cs:1318
static string Xdom_Node_Modify_ReadOnly
Definition SR.cs:1344
static string Xpn_BadPosition
Definition SR.cs:1316
static string Xml_DupAttributeName
Definition SR.cs:96
Definition SR.cs:7
static void DeleteToFollowingSibling(XmlNode node, XmlNode end)
static bool IsFollowingSibling(XmlNode left, [NotNullWhen(true)] XmlNode right)
override void WriteDocType(string name, string pubid, string sysid, string subset)
override void WriteProcessingInstruction(string name, string text)
override void WriteWhitespace(string text)
static readonly State[] s_changeState
override void WriteStartElement(string prefix, string localName, string ns)
void AddAttribute(XmlAttribute attr, XmlNode parent)
override void WriteRaw(string data)
override void WriteEndNamespaceDeclaration()
override void WriteNamespaceDeclaration(string prefix, string ns)
override void WriteString(string text)
override void WriteSurrogateCharEntity(char lowCh, char highCh)
readonly XmlDocument _document
override bool SupportsNamespaceDeclarationInChunks
override void WriteStartNamespaceDeclaration(string prefix)
XmlNamespaceManager NamespaceManager
DocumentXmlWriter(DocumentXmlWriterType type, XmlNode start, XmlDocument document)
override void WriteEndElement(string prefix, string localName, string ns)
override void WriteEntityRef(string name)
override XmlWriterSettings Settings
override void WriteChars(char[] buffer, int index, int count)
override void WriteStartAttribute(string prefix, string localName, string ns)
DocumentXPathNavigator _navigator
override void WriteStartDocument(bool standalone)
readonly DocumentXmlWriterType _type
override void WriteRaw(char[] buffer, int index, int count)
override void WriteFullEndElement(string prefix, string localName, string ns)
override void WriteXmlDeclaration(XmlStandalone standalone)
void AddChild(XmlNode node, XmlNode parent)
XmlNamespaceManager _namespaceManager
override void Close(WriteState currentState)
override void WriteCData(string text)
DocumentXPathNavigator Navigator
readonly List< XmlNode > _fragment
override void WriteComment(string text)
override void WriteXmlDeclaration(string xmldecl)
override void WriteCharEntity(char ch)
readonly XmlWriterSettings _settings
XmlAttribute Append(XmlAttribute node)
static void VerifyCharData(string data, ExceptionType exceptionType)
virtual XmlDeclaration CreateXmlDeclaration(string version, string? encoding, string? standalone)
virtual XmlWhitespace CreateWhitespace(string? text)
virtual XmlText CreateTextNode(string? text)
virtual XmlCDataSection CreateCDataSection(string? data)
virtual XmlProcessingInstruction CreateProcessingInstruction(string target, string data)
virtual XmlEntityReference CreateEntityReference(string name)
XmlElement CreateElement(string name)
virtual XmlComment CreateComment(string? data)
virtual XmlDocumentType CreateDocumentType(string name, string? publicId, string? systemId, string? internalSubset)
XmlAttribute CreateAttribute(string name)
static void ParseXmlDeclarationValue(string strValue, out string version, out string encoding, out string standalone)
Definition XmlLoader.cs:813
virtual ? string LookupNamespace(string prefix)
virtual ? string LookupPrefix(string uri)
virtual IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
virtual ? XmlNode AppendChild(XmlNode newChild)
Definition XmlNode.cs:739
virtual ? XmlNode PrependChild(XmlNode newChild)
Definition XmlNode.cs:734
virtual ? XmlNode ParentNode
Definition XmlNode.cs:76
virtual bool IsReadOnly
Definition XmlNode.cs:154
virtual XmlNode ReplaceChild(XmlNode newChild, XmlNode oldChild)
Definition XmlNode.cs:654
virtual ? XmlNode NextSibling
Definition XmlNode.cs:104
virtual ? XmlNode InsertAfter(XmlNode newChild, XmlNode? refChild)
Definition XmlNode.cs:548
virtual ? XmlNode InsertBefore(XmlNode newChild, XmlNode? refChild)
Definition XmlNode.cs:445
XmlNodeType NodeType
Definition XmlNode.cs:73
IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
string? LookupPrefix(string namespaceName)
string? LookupNamespace(string prefix)