本文整理汇总了C#中System.Xml.BufferBuilder类的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.BufferBuilder类的具体用法?C# System.Xml.BufferBuilder怎么用?C# System.Xml.BufferBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Xml.BufferBuilder类属于命名空间,在下文中一共展示了System.Xml.BufferBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1:
Task IDtdParserAdapter.ParseCommentAsync( BufferBuilder sb ) {
return reader.DtdParserProxy_ParseCommentAsync( sb );
}
示例2: 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));
}
//.........这里部分代码省略.........
示例3: ParseNamedCharRefInline
// Parses named character entity reference (& ' < > ").
// Returns -1 if the reference is not a character entity reference.
// Returns -2 if more data is needed in the buffer
// Otherwise
// - replaces the last character of the entity reference (';') with the referenced character (if expand == true)
// - returns position of the end of the character reference, that is of the character next to the original ';'
private int ParseNamedCharRefInline( int startPos, bool expand, BufferBuilder internalSubsetBuilder ) {
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 ) {
//.........这里部分代码省略.........
示例4: XmlTextReaderImpl
// This constructor is used when creating XmlTextReaderImpl reader via "XmlReader.Create(..)"
private XmlTextReaderImpl( XmlResolver resolver, XmlReaderSettings settings, XmlParserContext context ) {
#if ASYNC
useAsync = settings.Async;
#endif
v1Compat = false;
outerReader = this;
xmlContext = new XmlContext();
// create or get nametable and namespace manager from XmlParserContext
XmlNameTable nt = settings.NameTable;
if ( context == null ) {
if ( nt == null ) {
nt = new NameTable();
Debug.Assert( nameTableFromSettings == false );
}
else {
nameTableFromSettings = true;
}
nameTable = nt;
namespaceManager = new XmlNamespaceManager( nt );
}
else {
SetupFromParserContext( context, settings );
nt = nameTable;
}
nt.Add( string.Empty );
Xml = nt.Add( "xml" );
XmlNs = nt.Add( "xmlns" );
xmlResolver = resolver;
Debug.Assert( index == 0 );
nodes = new NodeData[ NodesInitialSize ];
nodes[0] = new NodeData();
curNode = nodes[0];
stringBuilder = new BufferBuilder();
#if !SILVERLIGHT
// Needed only for XmlTextReader (reporting of entities)
entityHandling = EntityHandling.ExpandEntities;
xmlResolverIsSet = settings.IsXmlResolverSet;
#endif
whitespaceHandling = ( settings.IgnoreWhitespace ) ? WhitespaceHandling.Significant : WhitespaceHandling.All;
normalize = true;
ignorePIs = settings.IgnoreProcessingInstructions;
ignoreComments = settings.IgnoreComments;
checkCharacters = settings.CheckCharacters;
lineNumberOffset = settings.LineNumberOffset;
linePositionOffset = settings.LinePositionOffset;
ps.lineNo = lineNumberOffset + 1;
ps.lineStartPos = - linePositionOffset - 1;
curNode.SetLineInfo( ps.LineNo - 1, ps.LinePos - 1 );
dtdProcessing = settings.DtdProcessing;
maxCharactersInDocument = settings.MaxCharactersInDocument;
maxCharactersFromEntities = settings.MaxCharactersFromEntities;
charactersInDocument = 0;
charactersFromEntities = 0;
fragmentParserContext = context;
parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl;
nextParsingFunction = ParsingFunction.DocumentContent;
switch ( settings.ConformanceLevel ) {
case ConformanceLevel.Auto:
fragmentType = XmlNodeType.None;
#if !SILVERLIGHT // Needed only for XmlTextReader
fragment = true;
#endif
break;
case ConformanceLevel.Fragment:
fragmentType = XmlNodeType.Element;
#if !SILVERLIGHT // Needed only for XmlTextReader
fragment = true;
#endif
break;
case ConformanceLevel.Document:
fragmentType = XmlNodeType.Document;
break;
default:
Debug.Assert( false );
goto case ConformanceLevel.Document;
}
}
示例5: 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;
}
}
示例6: DtdParserProxy_ParseNamedCharRef
internal int DtdParserProxy_ParseNamedCharRef( bool expand, BufferBuilder internalSubsetBuilder ) {
return this.ParseNamedCharRef( expand, internalSubsetBuilder );
}
示例7: DtdParserProxy_ParseComment
internal void DtdParserProxy_ParseComment( BufferBuilder sb ) {
Debug.Assert( parsingMode == ParsingMode.Full );
try {
if ( sb == null ) {
ParsingMode savedParsingMode = parsingMode;
parsingMode = ParsingMode.SkipNode;
ParseCDataOrComment( XmlNodeType.Comment );
parsingMode = savedParsingMode;
}
else {
NodeData originalCurNode = curNode;
curNode = AddNode( index + attrCount + 1, index );
ParseCDataOrComment( XmlNodeType.Comment );
curNode.CopyTo( 0, sb );
curNode = originalCurNode;
}
}
catch ( XmlException e ) {
#if !SILVERLIGHT
if ( e.ResString == Res.Xml_UnexpectedEOF && ps.entity != null ) {
SendValidationEvent( XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, null, ps.LineNo, ps.LinePos );
}
else {
throw;
}
#else
throw e;
#endif
}
}
示例8: DtdParserProxy_ParseNumericCharRefAsync
internal async Task<int> DtdParserProxy_ParseNumericCharRefAsync(BufferBuilder internalSubsetBuilder)
{
CheckAsyncCall();
var tuple_1 = await this.ParseNumericCharRefAsync(true, internalSubsetBuilder).ConfigureAwait(false);
return tuple_1.Item2;
}
示例9: DtdParserProxy_ParseNamedCharRefAsync
internal Task<int> DtdParserProxy_ParseNamedCharRefAsync(bool expand, BufferBuilder internalSubsetBuilder)
{
CheckAsyncCall();
return this.ParseNamedCharRefAsync(expand, internalSubsetBuilder);
}
示例10: ParseNumericCharRefAsync
// Parses numeric character entity reference (e.g.    ).
// - 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 ';'
// - if (expand == true) then ps.charPos is changed to point to the replaced character
private async Task<ValueTuple<EntityType, int>> ParseNumericCharRefAsync(bool expand, BufferBuilder internalSubsetBuilder)
{
EntityType entityType;
for (; ;)
{
int newPos;
int charCount;
switch (newPos = ParseNumericCharRefInline(_ps.charPos, expand, internalSubsetBuilder, out charCount, out entityType))
{
case -2:
// read new characters in the buffer
if (await ReadDataAsync().ConfigureAwait(false) == 0)
{
Throw(SR.Xml_UnexpectedEOF);
}
Debug.Assert(_ps.chars[_ps.charPos] == '&');
continue;
default:
if (expand)
{
_ps.charPos = newPos - charCount;
}
return new ValueTuple<EntityType, int>(entityType, newPos);
}
}
}
示例11: ParseNamedCharRefAsync
// Parses named character entity reference (& ' < > ").
// Returns -1 if the reference is not a character entity reference.
// Otherwise
// - replaces the last character of the entity reference (';') with the referenced character (if expand == true)
// - returns position of the end of the character reference, that is of the character next to the original ';'
// - if (expand == true) then ps.charPos is changed to point to the replaced character
private async Task<int> ParseNamedCharRefAsync(bool expand, BufferBuilder internalSubsetBuilder)
{
for (; ;)
{
int newPos;
switch (newPos = ParseNamedCharRefInline(_ps.charPos, expand, internalSubsetBuilder))
{
case -1:
return -1;
case -2:
// read new characters in the buffer
if (await ReadDataAsync().ConfigureAwait(false) == 0)
{
return -1;
}
Debug.Assert(_ps.chars[_ps.charPos] == '&');
continue;
default:
if (expand)
{
_ps.charPos = newPos - 1;
}
return newPos;
}
}
}
示例12: 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;
//.........这里部分代码省略.........
示例13: Initialize
//
// Initialization methods
//
private void Initialize(IDtdParserAdapter readerAdapter) {
Debug.Assert(readerAdapter != null);
this.readerAdapter = readerAdapter;
#if !SILVERLIGHT
this.readerAdapterWithValidation = readerAdapter as IDtdParserAdapterWithValidation;
#endif
nameTable = readerAdapter.NameTable;
#if !SILVERLIGHT
IDtdParserAdapterWithValidation raWithValidation = readerAdapter as IDtdParserAdapterWithValidation;
if (raWithValidation != null) {
this.validate = raWithValidation.DtdValidation;
}
IDtdParserAdapterV1 raV1 = readerAdapter as IDtdParserAdapterV1;
if (raV1 != null) {
v1Compat = raV1.V1CompatibilityMode;
this.normalize = raV1.Normalization;
this.supportNamespaces = raV1.Namespaces;
}
#endif
schemaInfo = new SchemaInfo();
#if !SILVERLIGHT
schemaInfo.SchemaType = SchemaType.DTD;
#endif
stringBuilder = new BufferBuilder();
Uri baseUri = readerAdapter.BaseUri;
if (baseUri != null) {
documentBaseUri = baseUri.ToString();
}
freeFloatingDtd = false;
}
示例14: ParseInDocumentDtdAsync
private async Task ParseInDocumentDtdAsync( bool saveInternalSubset ) {
LoadParsingBuffer();
scanningFunction = ScanningFunction.QName;
nextScaningFunction = ScanningFunction.Doctype1;
// doctype name
if ( await GetTokenAsync( false ).ConfigureAwait(false) != Token.QName ) {
OnUnexpectedError();
}
schemaInfo.DocTypeName = GetNameQualified( true );
// SYSTEM or PUBLIC id
Token token = await GetTokenAsync( false ).ConfigureAwait(false);
if ( token == Token.SYSTEM || token == Token.PUBLIC ) {
var tuple_0 = await ParseExternalIdAsync( token, Token.DOCTYPE).ConfigureAwait(false);
publicId = tuple_0.Item1;
systemId = tuple_0.Item2;
token = await GetTokenAsync( false).ConfigureAwait(false);
}
switch ( token ) {
case Token.LeftBracket:
if ( saveInternalSubset ) {
SaveParsingBuffer(); // this will cause saving the internal subset right from the point after '['
internalSubsetValueSb = new BufferBuilder();
}
await ParseInternalSubsetAsync().ConfigureAwait(false);
break;
case Token.GreaterThan:
break;
default:
OnUnexpectedError();
break;
}
SaveParsingBuffer();
if ( systemId != null && systemId.Length > 0 ) {
await ParseExternalSubsetAsync().ConfigureAwait(false);
}
}
示例15: DtdParserProxy_ParsePIAsync
internal async Task DtdParserProxy_ParsePIAsync(BufferBuilder sb)
{
CheckAsyncCall();
if (sb == null)
{
ParsingMode pm = _parsingMode;
_parsingMode = ParsingMode.SkipNode;
await ParsePIAsync(null).ConfigureAwait(false);
_parsingMode = pm;
}
else
{
await ParsePIAsync(sb).ConfigureAwait(false);
}
}