public XmlValidatingReader(String xmlFragment, XmlNodeType fragType, XmlParserContext context) { reader = new XmlTextReader(xmlFragment, fragType, context); entityHandling = EntityHandling.ExpandEntities; validationType = ValidationType.Auto; reader.Normalization = true; }
public XmlValidatingReader(String xmlFragment, XmlNodeType fragType, XmlParserContext context) { reader = new XmlTextReader(xmlFragment, fragType, context); entityHandling = EntityHandling.ExpandEntities; validationType = ValidationType.Auto; reader.Normalization = true; }
public XmlValidatingReader (XmlReader reader) { sourceReader = reader; xmlTextReader = reader as XmlTextReader; if (xmlTextReader == null) resolver = new XmlUrlResolver (); entityHandling = EntityHandling.ExpandEntities; validationType = ValidationType.Auto; storedCharacters = new StringBuilder (); }
// Constructors. public XmlValidatingReader(XmlReader reader) { this.reader = (reader as XmlTextReader); if(this.reader == null) { throw new ArgumentException (S._("Xml_NotTextReader"), "reader"); } entityHandling = EntityHandling.ExpandEntities; validationType = ValidationType.Auto; this.reader.Normalization = true; }
// Constructors. public XmlValidatingReader(XmlReader reader) { this.reader = (reader as XmlTextReader); if (this.reader == null) { throw new ArgumentException (S._("Xml_NotTextReader"), "reader"); } entityHandling = EntityHandling.ExpandEntities; validationType = ValidationType.Auto; this.reader.Normalization = true; }
public XmlValidatingReader(XmlReader reader) { sourceReader = reader; xmlTextReader = reader as XmlTextReader; if (xmlTextReader == null) { resolver = new XmlUrlResolver(); } entityHandling = EntityHandling.ExpandEntities; validationType = ValidationType.Auto; storedCharacters = new StringBuilder(); }
/// <summary>Initializes a new instance of the XmlValidatingReader class that validates the content returned from the given <see cref="T:System.Xml.XmlReader" />.</summary> /// <param name="reader">The XmlReader to read from while validating. The current implementation supports only <see cref="T:System.Xml.XmlTextReader" />. </param> /// <exception cref="T:System.ArgumentException">The reader specified is not an XmlTextReader. </exception> public XmlValidatingReader(XmlReader reader) { this.sourceReader = reader; this.xmlTextReader = (reader as XmlTextReader); if (this.xmlTextReader == null) { this.resolver = new XmlUrlResolver(); } this.entityHandling = EntityHandling.ExpandEntities; this.validationType = ValidationType.Auto; this.storedCharacters = new StringBuilder(); }
public QueryReaderSettings(XmlReader reader) { #pragma warning disable 618 XmlValidatingReader?valReader = reader as XmlValidatingReader; #pragma warning restore 618 if (valReader != null) { // Unwrap validation reader _validatingReader = true; reader = valReader.Impl.Reader; } _xmlReaderSettings = reader.Settings; if (_xmlReaderSettings != null) { _xmlReaderSettings = _xmlReaderSettings.Clone(); _xmlReaderSettings.NameTable = reader.NameTable; _xmlReaderSettings.CloseInput = true; _xmlReaderSettings.LineNumberOffset = 0; _xmlReaderSettings.LinePositionOffset = 0; XmlTextReaderImpl?impl = reader as XmlTextReaderImpl; if (impl != null) { _xmlReaderSettings.XmlResolver = impl.GetResolver(); } } else { _xmlNameTable = reader.NameTable; XmlTextReader?xmlTextReader = reader as XmlTextReader; if (xmlTextReader != null) { XmlTextReaderImpl impl = xmlTextReader.Impl; _entityHandling = impl.EntityHandling; _namespaces = impl.Namespaces; _normalization = impl.Normalization; _prohibitDtd = (impl.DtdProcessing == DtdProcessing.Prohibit); _whitespaceHandling = impl.WhitespaceHandling; _xmlResolver = impl.GetResolver(); } else { _entityHandling = EntityHandling.ExpandEntities; _namespaces = true; _normalization = true; _prohibitDtd = true; _whitespaceHandling = WhitespaceHandling.All; _xmlResolver = null; } } }
public QueryReaderSettings(XmlReader reader) { #pragma warning disable 618 XmlValidatingReader valReader = reader as XmlValidatingReader; #pragma warning restore 618 if (valReader != null) { // Unwrap validation reader validatingReader = true; reader = valReader.Impl.Reader; } xmlReaderSettings = reader.Settings; if (xmlReaderSettings != null) { xmlReaderSettings = xmlReaderSettings.Clone(); xmlReaderSettings.NameTable = reader.NameTable; xmlReaderSettings.CloseInput = true; xmlReaderSettings.LineNumberOffset = 0; xmlReaderSettings.LinePositionOffset = 0; XmlTextReaderImpl impl = reader as XmlTextReaderImpl; if (impl != null) { xmlReaderSettings.XmlResolver = impl.GetResolver(); } } else { xmlNameTable = reader.NameTable; XmlTextReader xmlTextReader = reader as XmlTextReader; if (xmlTextReader != null) { XmlTextReaderImpl impl = xmlTextReader.Impl; entityHandling = impl.EntityHandling; namespaces = impl.Namespaces; normalization = impl.Normalization; prohibitDtd = impl.ProhibitDtd; whitespaceHandling = impl.WhitespaceHandling; xmlResolver = impl.GetResolver(); } else { entityHandling = EntityHandling.ExpandEntities; namespaces = true; normalization = true; prohibitDtd = true; whitespaceHandling = WhitespaceHandling.All; xmlResolver = null; } } }
public QueryReaderSettings(XmlReader reader) { #pragma warning disable 618 XmlValidatingReader valReader = reader as XmlValidatingReader; #pragma warning restore 618 if (valReader != null) { // Unwrap validation reader _validatingReader = true; reader = valReader.Impl.Reader; } _xmlReaderSettings = reader.Settings; if (_xmlReaderSettings != null) { _xmlReaderSettings = _xmlReaderSettings.Clone(); _xmlReaderSettings.NameTable = reader.NameTable; _xmlReaderSettings.CloseInput = true; _xmlReaderSettings.LineNumberOffset = 0; _xmlReaderSettings.LinePositionOffset = 0; XmlTextReaderImpl impl = reader as XmlTextReaderImpl; if (impl != null) { _xmlReaderSettings.XmlResolver = impl.GetResolver(); } } else { _xmlNameTable = reader.NameTable; XmlTextReader xmlTextReader = reader as XmlTextReader; if (xmlTextReader != null) { XmlTextReaderImpl impl = xmlTextReader.Impl; _entityHandling = impl.EntityHandling; _namespaces = impl.Namespaces; _normalization = impl.Normalization; _prohibitDtd = (impl.DtdProcessing == DtdProcessing.Prohibit); _whitespaceHandling = impl.WhitespaceHandling; _xmlResolver = impl.GetResolver(); } else { _entityHandling = EntityHandling.ExpandEntities; _namespaces = true; _normalization = true; _prohibitDtd = true; _whitespaceHandling = WhitespaceHandling.All; _xmlResolver = null; } } }
public QueryReaderSettings(XmlReader reader) { XmlValidatingReader reader2 = reader as XmlValidatingReader; if (reader2 != null) { this.validatingReader = true; reader = reader2.Impl.Reader; } this.xmlReaderSettings = reader.Settings; if (this.xmlReaderSettings != null) { this.xmlReaderSettings = this.xmlReaderSettings.Clone(); this.xmlReaderSettings.NameTable = reader.NameTable; this.xmlReaderSettings.CloseInput = true; this.xmlReaderSettings.LineNumberOffset = 0; this.xmlReaderSettings.LinePositionOffset = 0; XmlTextReaderImpl impl = reader as XmlTextReaderImpl; if (impl != null) { this.xmlReaderSettings.XmlResolver = impl.GetResolver(); } } else { this.xmlNameTable = reader.NameTable; XmlTextReader reader3 = reader as XmlTextReader; if (reader3 != null) { XmlTextReaderImpl impl2 = reader3.Impl; this.entityHandling = impl2.EntityHandling; this.namespaces = impl2.Namespaces; this.normalization = impl2.Normalization; this.prohibitDtd = impl2.DtdProcessing == DtdProcessing.Prohibit; this.whitespaceHandling = impl2.WhitespaceHandling; this.xmlResolver = impl2.GetResolver(); } else { this.entityHandling = EntityHandling.ExpandEntities; this.namespaces = true; this.normalization = true; this.prohibitDtd = true; this.whitespaceHandling = WhitespaceHandling.All; this.xmlResolver = null; } } }
public QueryReaderSettings(XmlReader reader) { XmlValidatingReader reader2 = reader as XmlValidatingReader; if (reader2 != null) { this.validatingReader = true; reader = reader2.Impl.Reader; } this.xmlReaderSettings = reader.Settings; if (this.xmlReaderSettings != null) { this.xmlReaderSettings = this.xmlReaderSettings.Clone(); this.xmlReaderSettings.NameTable = reader.NameTable; this.xmlReaderSettings.CloseInput = true; this.xmlReaderSettings.LineNumberOffset = 0; this.xmlReaderSettings.LinePositionOffset = 0; XmlTextReaderImpl impl = reader as XmlTextReaderImpl; if (impl != null) { this.xmlReaderSettings.XmlResolver = impl.GetResolver(); } } else { this.xmlNameTable = reader.NameTable; XmlTextReader reader3 = reader as XmlTextReader; if (reader3 != null) { XmlTextReaderImpl impl2 = reader3.Impl; this.entityHandling = impl2.EntityHandling; this.namespaces = impl2.Namespaces; this.normalization = impl2.Normalization; this.prohibitDtd = impl2.DtdProcessing == DtdProcessing.Prohibit; this.whitespaceHandling = impl2.WhitespaceHandling; this.xmlResolver = impl2.GetResolver(); } else { this.entityHandling = EntityHandling.ExpandEntities; this.namespaces = true; this.normalization = true; this.prohibitDtd = true; this.whitespaceHandling = WhitespaceHandling.All; this.xmlResolver = null; } } }
internal override bool ReadAttributeValue(EntityHandling ehMode) { if ( this.PartialContentNodeType == XmlNodeType.Attribute) { return Read(); } if(!_IsScanner) { return ProduceExtraNodes(); } if (base.ReadAttributeValue(ehMode)) { _PrevXmlLang = _XmlLang; _PrevXmlSpace = _XmlSpace; return true; } return false; }
internal override bool ReadAttributeValue(EntityHandling ehMode) { if (this.PartialContentNodeType == XmlNodeType.Attribute) { return(Read()); } if (!_IsScanner) { return(ProduceExtraNodes()); } if (base.ReadAttributeValue(ehMode)) { _PrevXmlLang = _XmlLang; _PrevXmlSpace = _XmlSpace; return(true); } return(false); }
// // Public Methods and Properties // public virtual bool Load(XmlReader rXmlReader) { //Hook up your reader as my reader _rXmlReader = rXmlReader; if (rXmlReader is XmlTextReader) { _eWhitespaceMode = ((XmlTextReader)rXmlReader).WhitespaceHandling; _fNamespaces = ((XmlTextReader)rXmlReader).Namespaces; _eValidationMode = ValidationType.None; } #pragma warning disable 0618 if (rXmlReader is XmlValidatingReader) { if (((XmlValidatingReader)rXmlReader).Reader is XmlTextReader) { _eWhitespaceMode = ((XmlTextReader)((XmlValidatingReader)rXmlReader).Reader).WhitespaceHandling; } else { _eWhitespaceMode = WhitespaceHandling.None; } _fNamespaces = ((XmlValidatingReader)rXmlReader).Namespaces; _eValidationMode = ((XmlValidatingReader)rXmlReader).ValidationType; _eEntityMode = ((XmlValidatingReader)rXmlReader).EntityHandling; } #pragma warning restore 0618 DebugTrace("Setting ValidationMode=" + _eValidationMode.ToString()); DebugTrace("Setting EntityMode=" + _eEntityMode.ToString()); DebugTrace("Setting WhitespaceMode=" + _eWhitespaceMode.ToString()); //Process the Document try { _rDocumentRootNode = new CXmlNode("", "", XmlNodeType.Element); _rDocumentRootNode._eFlags = NodeFlags.DocumentRoot | NodeFlags.Indent; Process(_rDocumentRootNode); for (_rRootNode = _rDocumentRootNode.FirstChild; _rRootNode != null && _rRootNode.NodeType != XmlNodeType.Element; _rRootNode = _rRootNode.NextNode) { ; } } catch (Exception e) { //Unhook your reader _rXmlReader = null; _strParseError = e.ToString(); if (_fThrow) { throw (e); } if (_hr == 0) { _hr = -1; } return(false); } //Unhook your reader _rXmlReader = null; return(true); }
// This constructor is used when creating XmlTextReaderImpl reader via "XmlReader.Create(..)" private XmlTextReaderImpl(XmlResolver resolver, XmlReaderSettings settings, XmlParserContext context) { _useAsync = settings.Async; _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 StringBuilder(); // Needed only for XmlTextReader (reporting of entities) _entityHandling = EntityHandling.ExpandEntities; _xmlResolverIsSet = settings.IsXmlResolverSet; _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; _fragment = true; break; case ConformanceLevel.Fragment: _fragmentType = XmlNodeType.Element; _fragment = true; break; case ConformanceLevel.Document: _fragmentType = XmlNodeType.Document; break; default: Debug.Assert(false); goto case ConformanceLevel.Document; } }
// Initializes a new instance of the XmlTextReaderImpl class with the specified XmlNameTable. // This constructor is used when creating XmlTextReaderImpl for V1 XmlTextReader internal XmlTextReaderImpl(XmlNameTable nt) { Debug.Assert(nt != null); _v1Compat = true; _outerReader = this; _nameTable = nt; nt.Add(string.Empty); if (!System.Xml.XmlReaderSettings.EnableLegacyXmlSettings()) { _xmlResolver = null; } else { _xmlResolver = new XmlUrlResolver(); } _xml = nt.Add("xml"); _xmlNs = nt.Add("xmlns"); Debug.Assert(_index == 0); _nodes = new NodeData[NodesInitialSize]; _nodes[0] = new NodeData(); _curNode = _nodes[0]; _stringBuilder = new StringBuilder(); _xmlContext = new XmlContext(); _parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl; _nextParsingFunction = ParsingFunction.DocumentContent; _entityHandling = EntityHandling.ExpandCharEntities; _whitespaceHandling = WhitespaceHandling.All; _closeInput = true; _maxCharactersInDocument = 0; // Breaking change: entity expansion is enabled, but limit it to 10,000,000 chars (like XLinq) _maxCharactersFromEntities = (long)1e7; _charactersInDocument = 0; _charactersFromEntities = 0; _ps.lineNo = 1; _ps.lineStartPos = -1; }
// Initializes a new instance of the XmlTextReaderImpl class with the specified XmlNameTable. // This constructor is used when creating XmlTextReaderImpl for V1 XmlTextReader internal XmlTextReaderImpl( XmlNameTable nt ) { Debug.Assert( nt != null ); v1Compat = true; outerReader = this; nameTable = nt; nt.Add( string.Empty ); xmlResolver = new XmlUrlResolver(); Xml = nt.Add( "xml" ); XmlNs = nt.Add( "xmlns" ); Debug.Assert( index == 0 ); nodes = new NodeData[ NodesInitialSize ]; nodes[0] = new NodeData(); curNode = nodes[0]; stringBuilder = new BufferBuilder(); xmlContext = new XmlContext(); parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl; nextParsingFunction = ParsingFunction.DocumentContent; entityHandling = EntityHandling.ExpandCharEntities; whitespaceHandling = WhitespaceHandling.All; closeInput = true; maxCharactersInDocument = 0; // Breaking change: entity expansion is enabled, but limit it to 10,000,000 chars (like XLinq) maxCharactersFromEntities = (long)1e7; charactersInDocument = 0; charactersFromEntities = 0; ps.lineNo = 1; ps.lineStartPos = -1; }
// // Public Methods and Properties // public virtual bool Load(XmlReader rXmlReader) { //Hook up your reader as my reader _rXmlReader = rXmlReader; if (rXmlReader is XmlTextReader) { _eWhitespaceMode = ((XmlTextReader)rXmlReader).WhitespaceHandling; _fNamespaces = ((XmlTextReader)rXmlReader).Namespaces; _eValidationMode = ValidationType.None; // _eEntityMode = ((XmlValidatingReader)rXmlReader).EntityHandling; } #pragma warning disable 0618 if (rXmlReader is XmlValidatingReader) { if (((XmlValidatingReader)rXmlReader).Reader is XmlTextReader) { _eWhitespaceMode = ((XmlTextReader)((XmlValidatingReader)rXmlReader).Reader).WhitespaceHandling; } else { _eWhitespaceMode = WhitespaceHandling.None; } _fNamespaces = ((XmlValidatingReader)rXmlReader).Namespaces; _eValidationMode = ((XmlValidatingReader)rXmlReader).ValidationType; _eEntityMode = ((XmlValidatingReader)rXmlReader).EntityHandling; } #pragma warning restore 0618 DebugTrace("Setting ValidationMode=" + _eValidationMode.ToString()); DebugTrace("Setting EntityMode=" + _eEntityMode.ToString()); DebugTrace("Setting WhitespaceMode=" + _eWhitespaceMode.ToString()); //Process the Document try { _rDocumentRootNode = new CXmlNode("", "", XmlNodeType.Element); _rDocumentRootNode._eFlags = NodeFlags.DocumentRoot | NodeFlags.Indent; Process(_rDocumentRootNode); for (_rRootNode = _rDocumentRootNode.FirstChild; _rRootNode != null && _rRootNode.NodeType != XmlNodeType.Element; _rRootNode = _rRootNode.NextNode) ; } catch (Exception e) { //Unhook your reader _rXmlReader = null; _strParseError = e.ToString(); if (_fThrow) { throw (e); } if (_hr == 0) _hr = -1; return false; } //Unhook your reader _rXmlReader = null; return true; }
// non-overrides private void CopyProperties(EntityResolvingXmlReader other) { context = other.context; resolver = other.resolver; entity_handling = other.entity_handling; }
// non-overrides private void CopyProperties (EntityResolvingXmlReader other) { context = other.context; resolver = other.resolver; entity_handling = other.entity_handling; }
// This constructor is used when creating XmlTextReaderImpl reader via "XmlReader.Create(..)" private XmlTextReaderImpl( XmlResolver resolver, XmlReaderSettings settings, XmlParserContext context ) { 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(); entityHandling = EntityHandling.ExpandEntities; 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 ); prohibitDtd = settings.ProhibitDtd; fragmentParserContext = context; parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl; nextParsingFunction = ParsingFunction.DocumentContent; switch ( settings.ConformanceLevel ) { case ConformanceLevel.Auto: fragmentType = XmlNodeType.None; fragment = true; break; case ConformanceLevel.Fragment: fragmentType = XmlNodeType.Element; fragment = true; break; case ConformanceLevel.Document: fragmentType = XmlNodeType.Document; break; default: Debug.Assert( false ); goto case ConformanceLevel.Document; } }
// Initializes a new instance of the XmlTextReaderImpl class with the specified XmlNameTable. // This constructor is used when creating XmlTextReaderImpl for V1 XmlTextReader internal XmlTextReaderImpl( XmlNameTable nt ) { Debug.Assert( nt != null ); v1Compat = true; outerReader = this; nameTable = nt; nt.Add( string.Empty ); xmlResolver = new XmlUrlResolver(); Xml = nt.Add( "xml" ); XmlNs = nt.Add( "xmlns" ); Debug.Assert( index == 0 ); nodes = new NodeData[ NodesInitialSize ]; nodes[0] = new NodeData(); curNode = nodes[0]; stringBuilder = new BufferBuilder(); xmlContext = new XmlContext(); parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl; nextParsingFunction = ParsingFunction.DocumentContent; entityHandling = EntityHandling.ExpandCharEntities; whitespaceHandling = WhitespaceHandling.All; closeInput = true; ps.lineNo = 1; ps.lineStartPos = -1; }
internal virtual bool ReadAttributeValue(EntityHandling ehMode) { if (_PartialContentNodeType == XmlNodeType.Attribute) { return Read(); } if (_ReadState != ReadState.Interactive || GetAttributeCount() < 1 || _ReadCount < 0) return false; bool ret = true; XmlAttributeTokenInfo fld = _Fields[_ReadCount]; _AttributeTextToken.SchemaType = fld.SchemaType; _AttributeTextToken.TypedValue = fld.TypedValue; if (_NextFunction != _FinishAttributeIndex) { if (ehMode == EntityHandling.ExpandEntities) { ret = true; _CurrentToken = _AttributeTextToken; _CurrentToken.Value = fld.Value; _CurrentToken.NodeType = XmlNodeType.Text; _CurrentToken.Name = String.Empty; _CurrentToken.Depth = fld.Depth+1; _CurrentToken.LineNum = fld.ValueLineNum; _CurrentToken.LinePos = fld.ValueLinePos + 1; _NextFunction = _FinishAttributeIndex; _LastToken = XmlToken.EOF; goto cleanup; } else if (fld.ValueContainEntity == ValueContainEntity.None) { ret = true; _CurrentToken = _AttributeTextToken; _CurrentToken.Value = fld.ExpandValue; _CurrentToken.NodeType = XmlNodeType.Text; _CurrentToken.Name = String.Empty; _CurrentToken.Depth = fld.Depth+1; _CurrentToken.LineNum = fld.ValueLineNum; _CurrentToken.LinePos = fld.ValueLinePos + 1; _NextFunction = _FinishAttributeIndex; _LastToken = XmlToken.EOF; goto cleanup; } _MarkScannerCount = _ScannerStack.Length; // // push scanner when this function is called the first time // PushScanner(GetAttribValueScanner() , null, _BaseURI, _Fields, _ReadCount, _Used, _LastToken, _FinishAttributeIndex, false, null, 0, _Encoding, _StandAlone, _IsExternal, _IsExternal); } else if (_LastToken == XmlToken.EOF) { // // if there is more than one Scanner being pushed, it could be from ResolveEntity() // if (_ScannerStack.Length > 0 && (_MarkScannerCount+1) < _ScannerStack.Length) { if (!PopScannerWhenNotResolveEntity(ref _LastToken)) { ReadEndEntity(); _LastToken = PopScanner(); ret = true; goto cleanup; } } else { ret = false; goto cleanup; } } XmlBasicTokenInfo saveToken = _CurrentToken; _CurrentToken = _AttributeTextToken; bool noToken = false; do { noToken = ParseLiteralTokens(_Scanner, _CurrentToken, fld.Depth+1, ehMode, ref _LastToken); if (noToken && _LastToken == XmlToken.EOF) { if (_ScannerStack.Length > 0 && (_MarkScannerCount+1) < _ScannerStack.Length) { if (!PopScannerWhenNotResolveEntity(ref _LastToken)) { // // need to emit the EndEntity token // ReadEndEntity(); _LastToken = PopScanner(); noToken = false; } } else { _CurrentToken = saveToken; ret = false; goto cleanup; } } } while (noToken && _LastToken != XmlToken.EOF); _NextFunction = _FinishAttributeIndex; ret = true; cleanup: return ret; }
// This method is used in token view when ExpandEntities is false and // IgnoreEntities is false to return each text and entity reference as an // individual record. private bool ParseLiteralTokens(XmlScanner scanner, XmlBasicTokenInfo currToken, int newDepth, EntityHandling ehMode, ref int lastToken) { //String rawValue = String.Empty; String name = String.Empty, dataType = _StringName; XmlNodeType nodeType = XmlNodeType.Text; int startPos = -1, erPos = -1; int LineNum = _Scanner.LineNum; int LinePos = _Scanner.LinePos; bool hasToken = false/*, hasER = false*/, retValue = false; char ch='\0'; int state = 2; _StringBuilder.Length = 0; do { switch (state) { case 2: erPos = scanner.CurrentPos; lastToken = scanner.ScanLiteral(true, false, false, false); switch (lastToken) { case XmlToken.EOF: // reached the end of the literal. state = -1; if (!hasToken) { retValue = true; goto cleanup; } goto seeToken; case XmlToken.TEXT: startPos = (hasToken == true) ? startPos : scanner.StartPos; _StringBuilder.Append(scanner.InternalBuffer, scanner.TextOffset, scanner.TextLength); hasToken = true; nodeType = XmlNodeType.Text; state = 2; break; case XmlToken.ENTITYREF: startPos = (hasToken == true) ? startPos : scanner.StartPos - 1; ch = scanner.ScanNamedEntity(); name = scanner.GetTextAtom(); // // ch == 0 if general entity // ch != 0 if build in entity, for example: < // if (ch == 0 && _CheckNamespaces && _Scanner.Colon() != -1) throw new XmlException(Res.Xml_BadNameChar, XmlException.BuildCharExceptionStr(':'), _Scanner.LineNum, _Scanner.LinePos); if (ch != 0) { _StringBuilder.Append(ch); dataType = "Char"; scanner.Advance(); hasToken = true; //hasER = true; _NextState = 2; name = String.Empty; nodeType = XmlNodeType.Text; } else if (hasToken) { // First return the text we have up to this point. state = 11; } else { // Return the entity reference as a node. state = 10; nodeType = XmlNodeType.EntityReference; } break; case XmlToken.NUMENTREF: startPos = (hasToken == true) ? startPos : scanner.StartPos - 1; hasToken = true; //hasER = true; _StringBuilder.Append(scanner.ScanDecEntity()); state = 2; break; case XmlToken.HEXENTREF: startPos = (hasToken == true) ? startPos : scanner.StartPos - 1; hasToken = true; //hasER = true; _StringBuilder.Append(scanner.ScanHexEntity()); state = 2; break; default: throw new XmlException(Res.Xml_InternalError); } break; case 9: scanner.Advance(); hasToken = true; //hasER = true; state = 2; goto seeToken; case 10: scanner.Advance(); hasToken = true; //hasER = true; state = 2; // general entity special case currToken.Value = String.Empty; LinePos += 1; goto otherToken; case 11: scanner.CurrentPos = erPos; state = 2; name = String.Empty; goto seeToken; case 12: state = 2; ParseTag(); goto cleanup; default: Debug.Assert(false, "unknown state within ParseBeginTag()"); break; } } while (true); seeToken: currToken.SetValue(_StringBuilder); dataType = _StringName; // // there is no rawValue // if (hasER) // rawValue = scanner.GetText(startPos, scanner.CurrentPos - startPos); //currToken.RawValue = rawValue; otherToken: currToken.Name = name; currToken.LineNum = LineNum; currToken.LinePos = LinePos; currToken.NodeType = nodeType; currToken.Depth = newDepth; cleanup: return retValue; }
private void Init () { allowMultipleRoot = false; elementNames = new TagName [10]; valueBuffer = new StringBuilder (); binaryCharGetter = new XmlReaderBinarySupport.CharGetter (ReadChars); #if USE_NAME_BUFFER nameBuffer = new char [initialNameCapacity]; #endif checkCharacters = true; if (Settings != null) checkCharacters = Settings.CheckCharacters; prohibitDtd = false; closeInput = true; entityHandling = EntityHandling.ExpandCharEntities; peekCharsIndex = 0; if (peekChars == null) peekChars = new char [peekCharCapacity]; peekCharsLength = -1; curNodePeekIndex = -1; // read from start line = 1; column = 1; currentLinkedNodeLineNumber = currentLinkedNodeLinePosition = 0; Clear (); }
public override bool Read () { if (currentTextValue != null) shouldResetCurrentTextValue = true; if (currentAttribute >= 0) MoveToElement (); currentElement = null; currentAttribute = -1; consumedAttribute = false; attributeCount = 0; isWhitespace = false; isSignificantWhitespace = false; isText = false; bool b = ReadContent () || currentTextValue != null; if (!b && #if NET_2_0 (Settings == null || (Settings.ValidationFlags & XmlSchemaValidationFlags.ProcessIdentityConstraints) == 0) && #endif this.missingIDReferences.Count > 0) { this.HandleError ("Missing ID reference was found: " + String.Join (",", missingIDReferences.ToArray (typeof (string)) as string []), XmlSeverityType.Error); // Don't output the same errors so many times. this.missingIDReferences.Clear (); } if (validatingReader != null) EntityHandling = validatingReader.EntityHandling; return b; }
// This constructor is used when creating XmlTextReader reader via "XmlReader.Create(..)" private XmlTextReader(XmlReaderSettings settings) { xmlContext = new XmlContext(); // create nametable XmlNameTable nt = settings.NameTable; if (nt == null) { nt = new NameTable(); Debug.Assert(nameTableFromSettings == false); } else { nameTableFromSettings = true; } nameTable = nt; nt.Add(""); Xml = nt.Add("xml"); XmlNs = nt.Add("xmlns"); Debug.Assert(index == 0); nodes = new NodeData[NodesInitialSize]; nodes[0] = new NodeData(); curNode = nodes[0]; stringBuilder = new BufferBuilder(); entityHandling = EntityHandling.ExpandEntities; 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); parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl; nextParsingFunction = ParsingFunction.DocumentContent; switch (settings.ConformanceLevel) { case ConformanceLevel.Auto: fragmentType = XmlNodeType.None; break; case ConformanceLevel.Fragment: fragmentType = XmlNodeType.Element; break; case ConformanceLevel.Document: fragmentType = XmlNodeType.Document; break; default: Debug.Assert(false); goto case ConformanceLevel.Document; } }