160 private static readonly
string[]
s_stateName =
new string[10] {
"Start",
"Prolog",
"PostDTD",
"Element",
"Attribute",
"Content",
"AttrOnly",
"Epilog",
"Error",
"Closed" };
164 "PI",
"Doctype",
"Comment",
"CData",
"StartElement",
"EndElement",
"LongEndElement",
"StartAttribute",
"EndAttribute",
"Content",
165 "Base64",
"RawData",
"Whitespace",
"Empty"
386 private static readonly
char[]
s_closeTagEnd =
new char[3] {
' ',
'/',
'>' };
462 for (
int i = 0; i < 64; i++)
469 public char QuoteChar
486 public override WriteState WriteState
493 return WriteState.Start;
496 return WriteState.Prolog;
498 return WriteState.Element;
499 case State.Attribute:
501 return WriteState.Attribute;
504 return WriteState.Content;
506 return WriteState.Error;
508 return WriteState.Closed;
510 return WriteState.Error;
515 public override XmlSpace XmlSpace
519 for (
int num =
_top; num > 0; num--)
527 return XmlSpace.None;
531 public override string?
XmlLang
535 for (
int num =
_top; num > 0; num--)
549 char[]
array =
new char[64];
554 private XmlTextWriter()
575 if (encoding !=
null)
640 AutoComplete(Token.Doctype);
651 else if (
sysid !=
null)
676 AutoComplete(Token.StartElement);
696 string text = FindPrefix(ns);
703 PushNamespace(
null, ns, declared:
false);
706 else if (
prefix.Length == 0)
708 PushNamespace(
null, ns, declared:
false);
727 else if ((ns !=
null && ns.Length != 0) || (
prefix !=
null &&
prefix.Length != 0))
755 AutoComplete(Token.StartAttribute);
763 if (ns ==
"http://www.w3.org/2000/xmlns/" &&
prefix ==
null && localName !=
"xmlns")
769 if (localName ==
"lang")
773 else if (localName ==
"space")
778 else if (
prefix ==
"xmlns")
780 if (
"http://www.w3.org/2000/xmlns/" != ns && ns !=
null)
784 if (localName ==
null || localName.Length == 0)
796 else if (
prefix ==
null && localName ==
"xmlns")
798 if (
"http://www.w3.org/2000/xmlns/" != ns && ns !=
null)
812 else if (ns.Length == 0)
823 string text = FindPrefix(ns);
832 prefix = GeneratePrefix();
845 if ((ns !=
null && ns.Length != 0) || (
prefix !=
null &&
prefix.Length != 0))
849 if (localName ==
"xml:lang")
853 else if (localName ==
"xml:space")
879 AutoComplete(Token.EndAttribute);
892 AutoComplete(Token.CData);
893 if (
text !=
null &&
text.Contains(
"]]>"))
915 if (
text !=
null && (
text.Contains(
"--") || (
text.Length != 0 &&
text[
text.Length - 1] ==
'-')))
919 AutoComplete(Token.Comment);
938 if (
text !=
null &&
text.Contains(
"?>"))
946 AutoComplete(Token.PI);
961 AutoComplete(Token.Content);
975 AutoComplete(Token.Content);
993 if (!XmlCharType.IsOnlyWhitespace(
ws))
997 AutoComplete(Token.Whitespace);
1011 if (
text !=
null &&
text.Length != 0)
1013 AutoComplete(Token.Content);
1028 AutoComplete(Token.Content);
1042 AutoComplete(Token.Content);
1056 AutoComplete(Token.RawData);
1066 public override void WriteRaw(
string data)
1070 AutoComplete(Token.RawData);
1086 AutoComplete(Token.Base64);
1106 AutoComplete(Token.Content);
1116 public override void Close()
1132 public override void Flush()
1137 public override void WriteName(
string name)
1141 AutoComplete(Token.Content);
1155 AutoComplete(Token.Content);
1160 string text = FindPrefix(ns);
1167 text = GeneratePrefix();
1168 PushNamespace(
text, ns, declared:
false);
1170 if (
text.Length != 0)
1177 else if (ns !=
null && ns.Length != 0)
1192 if (ns ==
null || ns.Length == 0)
1196 string text = FindPrefix(ns);
1199 text =
string.Empty;
1208 AutoComplete(Token.Content);
1209 if (name ==
null ||
name.Length == 0)
1213 if (!ValidateNames.IsNmtokenNoNamespaces(name))
1267 private void AutoComplete(Token token)
1278 if (
state == State.Error)
1293 case Token.StartElement:
1303 if (token == Token.CData)
1312 case Token.EndElement:
1313 case Token.LongEndElement:
1324 token = Token.LongEndElement;
1332 state = State.Epilog;
1335 case Token.StartAttribute:
1350 case Token.EndAttribute:
1359 case Token.Whitespace:
1364 goto case Token.Base64;
1370 if (
state == State.Content)
1421 PopNamespaces(prevNsTop + 1,
_nsTop);
1504 private void PushNamespace(
string prefix,
string ns,
bool declared)
1506 if (
"http://www.w3.org/2000/xmlns/" == ns)
1516 case NamespaceState.Uninitialized:
1517 case NamespaceState.NotDeclaredButInScope:
1520 case NamespaceState.DeclaredButNotWrittenOut:
1526 if (
prefix.Length != 0 && ns.Length == 0)
1530 int num = LookupNamespace(
prefix);
1531 if (num != -1 &&
_nsStack[num].ns == ns)
1539 if (declared && num != -1 && num >
_stack[
_top].prevNsTop)
1543 AddNamespace(
prefix, ns, declared);
1546 private void AddNamespace(
string prefix,
string ns,
bool declared)
1558 AddToNamespaceHashtable(num);
1564 for (
int i = 0;
i <= num;
i++)
1566 AddToNamespaceHashtable(i);
1585 if (
_nsStack[num].prevNsIndex == -1)
1596 private string GeneratePrefix()
1614 private int LookupNamespace(
string prefix)
1625 for (
int num =
_nsTop; num >= 0; num--)
1658 private string FindPrefix(
string ns)
1660 for (
int num =
_nsTop; num >= 0; num--)
1676 private void ValidateName(
string name,
bool isNCName)
1678 if (name ==
null ||
name.Length == 0)
1686 int num2 = ValidateNames.ParseNCName(name);
1699 num2 += ValidateNames.ParseNmtoken(name,
num2);
1702 else if (ValidateNames.IsNameNoNamespaces(name))
1714 case SpecialAttr.XmlLang:
1717 case SpecialAttr.XmlSpace:
1730 case SpecialAttr.XmlNs:
1745 private void PushStack()
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
virtual void Dispose(bool disposing)
virtual void Write(char value)
static byte Min(byte val1, byte val2)
static string Xml_InvalidPiChars
static string Xml_InvalidXmlSpace
static string Xml_InvalidNameChars
static string Xml_PrefixForEmptyNs
static string Xml_InvalidPrefix
static string Xml_NotInWriteState
static string Xml_InvalidCommentChars
static string Xml_EmptyName
static string Xml_ClosedOrError
static string Xml_CanNotBindToReservedNamespace
static string Xml_NoNamespaces
static string Xml_NotTheFirst
static string Xml_NoStartTag
static string Xml_WrongToken
static string Format(string resourceFormat, object p1)
static string Xml_DupXmlDecl
static string Xml_XmlnsBelongsToReservedNs
static string Xml_InvalidQuote
static string Xml_UndefNamespace
static string Xml_InvalidCDataChars
static string Xml_UndefPrefix
static string Xml_NonWhitespace
static string Xml_InvalidOperation
static string Xml_InvalidIndentation
void Encode(byte[] buffer, int index, int count)
void WriteCharEntity(char ch)
void StartAttribute(bool cacheAttrValue)
void WriteRawWithSurrogateChecking(string text)
void WriteEntityRef(string name)
void Write(char[] array, int offset, int count)
void WriteSurrogateCharEntity(char lowChar, char highChar)
void WriteRaw(char[] array, int offset, int count)
XmlTextWriterBase64Encoder _base64Encoder
readonly TextWriter _textWriter
static readonly string[] s_tokenName
Dictionary< string, int > _nsHashtable
@ DeclaredButNotWrittenOut
static readonly char[] s_selfClosingTagOpen
static readonly State[] s_stateTableDefault
readonly XmlTextEncoder _xmlEncoder
static readonly char[] s_closeTagEnd
readonly Encoding _encoding
static readonly char[] s_defaultIndentChars
static readonly State[] s_stateTableDocument
static readonly string[] s_stateName
virtual void WriteName(string name)
void WriteCData(string? text)
void WriteComment(string? text)
void WriteProcessingInstruction(string name, string? text)
virtual void WriteNmToken(string name)
void WriteSurrogateCharEntity(char lowChar, char highChar)
void WriteEntityRef(string name)
void WriteString(string? text)
string? LookupPrefix(string ns)
void WriteChars(char[] buffer, int index, int count)
void WriteFullEndElement()
void WriteBase64(byte[] buffer, int index, int count)
void WriteCharEntity(char ch)
virtual void WriteQualifiedName(string localName, string? ns)
void WriteStartDocument()
void WriteRaw(char[] buffer, int index, int count)
void WriteStartAttribute(string localName, string? ns)
virtual void WriteBinHex(byte[] buffer, int index, int count)
void WriteWhitespace(string? ws)
void WriteDocType(string name, string? pubid, string? sysid, string? subset)
void WriteStartElement(string localName, string? ns)
void AppendLiteral(string value)
void AppendFormatted(ReadOnlySpan< char > value)
void Set(string prefix, string ns, bool declared)
NamespaceState defaultNsState