本文整理汇总了C#中System.Xml.BufferBuilder.Append方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.BufferBuilder.Append方法的具体用法?C# System.Xml.BufferBuilder.Append怎么用?C# System.Xml.BufferBuilder.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.BufferBuilder
的用法示例。
在下文中一共展示了System.Xml.BufferBuilder.Append方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalReadContentAsString
internal string InternalReadContentAsString()
{
string value = string.Empty;
BufferBuilder sb = null;
do
{
switch (this.NodeType)
{
case XmlNodeType.Attribute:
return this.Value;
case XmlNodeType.Text:
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
case XmlNodeType.CDATA:
// merge text content
if (value.Length == 0)
{
value = this.Value;
}
else
{
if (sb == null)
{
sb = new BufferBuilder();
sb.Append(value);
}
sb.Append(this.Value);
}
break;
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.Comment:
case XmlNodeType.EndEntity:
// skip comments, pis and end entity nodes
break;
case XmlNodeType.EntityReference:
if (this.CanResolveEntity)
{
this.ResolveEntity();
break;
}
goto default;
case XmlNodeType.EndElement:
default:
goto ReturnContent;
}
} while ((this.AttributeCount != 0) ? this.ReadAttributeValue() : this.Read());
ReturnContent:
return (sb == null) ? value : sb.ToString();
}
示例2: ParseNamedCharRefInline
//.........这里部分代码省略.........
Debug.Assert( startPos < ps.charsUsed );
Debug.Assert( ps.chars[startPos] == '&' );
Debug.Assert( ps.chars[startPos + 1] != '#' );
int pos = startPos + 1;
char[] chars = ps.chars;
char ch;
switch ( chars[pos] ) {
// ' or &
case 'a':
pos++;
// &
if ( chars[pos] == 'm' ) {
if ( ps.charsUsed - pos >= 3 ) {
if ( chars[pos+1] == 'p' && chars[pos+2] == ';' ) {
pos += 3;
ch = '&';
goto FoundCharRef;
}
else {
return -1;
}
}
}
// '
else if ( chars[pos] == 'p' ) {
if ( ps.charsUsed - pos >= 4 ) {
if ( chars[pos+1] == 'o' && chars[pos+2] == 's' &&
chars[pos+3] == ';' ) {
pos += 4;
ch = '\'';
goto FoundCharRef;
}
else {
return -1;
}
}
}
else if ( pos < ps.charsUsed ) {
return -1;
}
break;
// &guot;
case 'q':
if ( ps.charsUsed - pos >= 5 ) {
if ( chars[pos+1] == 'u' && chars[pos+2] == 'o' &&
chars[pos+3] == 't' && chars[pos+4] == ';' ) {
pos += 5;
ch = '"';
goto FoundCharRef;
}
else {
return -1;
}
}
break;
// <
case 'l':
if ( ps.charsUsed - pos >= 3 ) {
if ( chars[pos+1] == 't' && chars[pos+2] == ';' ) {
pos += 3;
ch = '<';
goto FoundCharRef;
}
else {
return -1;
}
}
break;
// >
case 'g':
if ( ps.charsUsed - pos >= 3 ) {
if ( chars[pos+1] == 't' && chars[pos+2] == ';' ) {
pos += 3;
ch = '>';
goto FoundCharRef;
}
else {
return -1;
}
}
break;
default:
return -1;
}
// need more data in the buffer
return -2;
FoundCharRef:
Debug.Assert( pos > 0 );
if ( expand ) {
if ( internalSubsetBuilder != null ) {
internalSubsetBuilder.Append( ps.chars, ps.charPos, pos - ps.charPos );
}
ps.chars[pos-1] = ch;
}
return pos;
}
示例3: ParseNumericCharRefInline
// Parses numeric character entity reference (e.g.    ).
// Returns -2 if more data is needed in the buffer
// Otherwise
// - replaces the last one or two character of the entity reference (';' and the character before) with the referenced
// character or surrogates pair (if expand == true)
// - returns position of the end of the character reference, that is of the character next to the original ';'
private int ParseNumericCharRefInline( int startPos, bool expand, BufferBuilder internalSubsetBuilder, out int charCount, out EntityType entityType ) {
Debug.Assert( ps.chars[startPos] == '&' && ps.chars[startPos + 1] == '#' );
int val;
int pos;
char[] chars;
val = 0;
string badDigitExceptionString = null;
chars = ps.chars;
pos = startPos + 2;
charCount = 0;
int digitPos = 0;
try {
if ( chars[pos] == 'x' ) {
pos++;
digitPos = pos;
badDigitExceptionString = Res.Xml_BadHexEntity;
for (;;) {
char ch = chars[pos];
if ( ch >= '0' && ch <= '9' )
val = checked(val * 16 + ch - '0');
else if ( ch >= 'a' && ch <= 'f' )
val = checked(val * 16 + 10 + ch - 'a');
else if ( ch >= 'A' && ch <= 'F' )
val = checked(val * 16 + 10 + ch - 'A');
else
break;
pos++;
}
entityType = EntityType.CharacterHex;
}
else if ( pos < ps.charsUsed ) {
digitPos = pos;
badDigitExceptionString = Res.Xml_BadDecimalEntity;
while ( chars[pos] >= '0' && chars[pos] <= '9' ) {
val = checked(val * 10 + chars[pos] - '0');
pos++;
}
entityType = EntityType.CharacterDec;
}
else {
// need more data in the buffer
entityType = EntityType.Skipped;
return -2;
}
}
catch (OverflowException e) {
ps.charPos = pos;
entityType = EntityType.Skipped;
Throw(Res.Xml_CharEntityOverflow, (string)null, e);
}
if ( chars[pos] != ';' || digitPos == pos) {
if ( pos == ps.charsUsed ) {
// need more data in the buffer
return -2;
}
else {
Throw( pos, badDigitExceptionString );
}
}
// simple character
if ( val <= char.MaxValue ) {
char ch = (char)val;
if ( !xmlCharType.IsCharData(ch) &&
( ( v1Compat && normalize ) || (!v1Compat && checkCharacters ) ) ) {
Throw((ps.chars[startPos + 2] == 'x') ? startPos + 3 : startPos + 2, Res.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(ch, '\0'));
}
if ( expand ) {
if ( internalSubsetBuilder != null ) {
internalSubsetBuilder.Append( ps.chars, ps.charPos, pos - ps.charPos + 1 );
}
chars[pos] = ch;
}
charCount = 1;
return pos + 1;
}
// surrogate
else {
char low, high;
XmlCharType.SplitSurrogateChar(val, out low, out high);
if ( normalize ) {
if ( XmlCharType.IsHighSurrogate( high ) ) {
if ( XmlCharType.IsLowSurrogate( low ) ) {
goto Return;
}
}
Throw((ps.chars[startPos + 2] == 'x') ? startPos + 3 : startPos + 2, Res.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(high, low));
}
//.........这里部分代码省略.........
示例4: EatWhitespaces
private int EatWhitespaces( BufferBuilder sb ) {
int pos = ps.charPos;
int wsCount = 0;
char[] chars = ps.chars;
for (;;) {
for (;;) {
switch ( chars[pos] ) {
case (char)0xA:
pos++;
OnNewLine( pos );
continue;
case (char)0xD:
if ( chars[pos+1] == (char)0xA ) {
int tmp1 = pos - ps.charPos;
if ( sb != null && !ps.eolNormalized ) {
if ( tmp1 > 0 ) {
sb.Append( chars, ps.charPos, tmp1 );
wsCount += tmp1;
}
ps.charPos = pos + 1;
}
pos += 2;
}
else if ( pos+1 < ps.charsUsed || ps.isEof ) {
if ( !ps.eolNormalized ) {
chars[pos] = (char)0xA; // EOL normalization of 0xD
}
pos++;
}
else {
goto ReadData;
}
OnNewLine( pos );
continue;
case (char)0x9:
case (char)0x20:
pos++;
continue;
default:
if ( pos == ps.charsUsed ) {
goto ReadData;
}
else {
int tmp2 = pos - ps.charPos;
if ( tmp2 > 0 ) {
if ( sb != null ) {
sb.Append( ps.chars, ps.charPos, tmp2 );
}
ps.charPos = pos;
wsCount += tmp2;
}
return wsCount;
}
}
}
ReadData:
int tmp3 = pos - ps.charPos;
if ( tmp3 > 0 ) {
if ( sb != null ) {
sb.Append( ps.chars, ps.charPos, tmp3 );
}
ps.charPos = pos;
wsCount += tmp3;
}
if ( ReadData() == 0 ) {
if ( ps.charsUsed - ps.charPos == 0 ) {
return wsCount;
}
if ( ps.chars[ps.charPos] != (char)0xD ) {
Debug.Assert( false, "We should never get to this point." );
Throw( Res.Xml_UnexpectedEOF1 );
}
Debug.Assert( ps.isEof );
}
pos = ps.charPos;
chars = ps.chars;
}
}
示例5: ParsePI
// Parses processing instruction; if piInDtdStringBuilder != null, the processing instruction is in DTD and
// it will be saved in the passed string builder (target, whitespace & value).
private bool ParsePI( BufferBuilder piInDtdStringBuilder ) {
if ( parsingMode == ParsingMode.Full ) {
curNode.SetLineInfo( ps.LineNo, ps.LinePos );
}
Debug.Assert( stringBuilder.Length == 0 );
// parse target name
int nameEndPos = ParseName();
string target = nameTable.Add( ps.chars, ps.charPos, nameEndPos - ps.charPos );
if ( string.Compare( target, "xml", StringComparison.OrdinalIgnoreCase ) == 0 ) {
Throw( target.Equals( "xml" ) ? Res.Xml_XmlDeclNotFirst : Res.Xml_InvalidPIName, target );
}
ps.charPos = nameEndPos;
if ( piInDtdStringBuilder == null ) {
if ( !ignorePIs && parsingMode == ParsingMode.Full ) {
curNode.SetNamedNode( XmlNodeType.ProcessingInstruction, target );
}
}
else {
piInDtdStringBuilder.Append( target );
}
// check mandatory whitespace
char ch = ps.chars[ps.charPos];
Debug.Assert( ps.charPos < ps.charsUsed );
if ( EatWhitespaces( piInDtdStringBuilder ) == 0 ) {
if ( ps.charsUsed - ps.charPos < 2 ) {
ReadData();
}
if ( ch != '?' || ps.chars[ps.charPos+1] != '>' ) {
Throw( Res.Xml_BadNameChar, XmlException.BuildCharExceptionArgs( ps.chars, ps.charsUsed, ps.charPos ) );
}
}
// scan processing instruction value
int startPos, endPos;
if ( ParsePIValue( out startPos, out endPos ) ) {
if ( piInDtdStringBuilder == null ) {
if ( ignorePIs ) {
return false;
}
if ( parsingMode == ParsingMode.Full ) {
curNode.SetValue( ps.chars, startPos, endPos - startPos );
}
}
else {
piInDtdStringBuilder.Append( ps.chars, startPos, endPos - startPos );
}
}
else {
BufferBuilder sb;
if ( piInDtdStringBuilder == null ) {
if ( ignorePIs || parsingMode != ParsingMode.Full ) {
while ( !ParsePIValue( out startPos, out endPos ) );
return false;
}
sb = stringBuilder;
Debug.Assert( stringBuilder.Length == 0 );
}
else {
sb = piInDtdStringBuilder;
}
do {
sb.Append( ps.chars, startPos, endPos - startPos );
} while ( !ParsePIValue( out startPos, out endPos ) );
sb.Append( ps.chars, startPos, endPos - startPos );
if ( piInDtdStringBuilder == null ) {
curNode.SetValue( stringBuilder.ToString() );
stringBuilder.Length = 0;
}
}
return true;
}
示例6: ParsePIAsync
// Parses processing instruction; if piInDtdStringBuilder != null, the processing instruction is in DTD and
// it will be saved in the passed string builder (target, whitespace & value).
private async Task<bool> ParsePIAsync(BufferBuilder piInDtdStringBuilder)
{
if (_parsingMode == ParsingMode.Full)
{
_curNode.SetLineInfo(_ps.LineNo, _ps.LinePos);
}
Debug.Assert(_stringBuilder.Length == 0);
// parse target name
int nameEndPos = await ParseNameAsync().ConfigureAwait(false);
string target = _nameTable.Add(_ps.chars, _ps.charPos, nameEndPos - _ps.charPos);
if (string.Equals(target, "xml", StringComparison.OrdinalIgnoreCase))
{
Throw(target.Equals("xml") ? SR.Xml_XmlDeclNotFirst : SR.Xml_InvalidPIName, target);
}
_ps.charPos = nameEndPos;
if (piInDtdStringBuilder == null)
{
if (!_ignorePIs && _parsingMode == ParsingMode.Full)
{
_curNode.SetNamedNode(XmlNodeType.ProcessingInstruction, target);
}
}
else
{
piInDtdStringBuilder.Append(target);
}
// check mandatory whitespace
char ch = _ps.chars[_ps.charPos];
Debug.Assert(_ps.charPos < _ps.charsUsed);
if (await EatWhitespacesAsync(piInDtdStringBuilder).ConfigureAwait(false) == 0)
{
if (_ps.charsUsed - _ps.charPos < 2)
{
await ReadDataAsync().ConfigureAwait(false);
}
if (ch != '?' || _ps.chars[_ps.charPos + 1] != '>')
{
Throw(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(_ps.chars, _ps.charsUsed, _ps.charPos));
}
}
// scan processing instruction value
int startPos, endPos;
var tuple_18 = await ParsePIValueAsync().ConfigureAwait(false);
startPos = tuple_18.Item1;
endPos = tuple_18.Item2;
if (tuple_18.Item3)
{
if (piInDtdStringBuilder == null)
{
if (_ignorePIs)
{
return false;
}
if (_parsingMode == ParsingMode.Full)
{
_curNode.SetValue(_ps.chars, startPos, endPos - startPos);
}
}
else
{
piInDtdStringBuilder.Append(_ps.chars, startPos, endPos - startPos);
}
}
else
{
BufferBuilder sb;
if (piInDtdStringBuilder == null)
{
if (_ignorePIs || _parsingMode != ParsingMode.Full)
{
ValueTuple<int, int, bool> tuple_19;
do
{
tuple_19 = await ParsePIValueAsync().ConfigureAwait(false);
startPos = tuple_19.Item1;
endPos = tuple_19.Item2;
} while (!tuple_19.Item3);
return false;
}
sb = _stringBuilder;
Debug.Assert(_stringBuilder.Length == 0);
}
else
{
sb = piInDtdStringBuilder;
}
ValueTuple<int, int, bool> tuple_20;
//.........这里部分代码省略.........