/// <include file='doc\XmlTextReader.uex' path='docs/doc[@for="XmlTextReader.MoveToElement"]/*' /> /// <devdoc> /// <para> /// Moves to the element that contains the current attribute node. /// </para> /// </devdoc> public override bool MoveToElement() { if (_CurrentToken.IsAttributeText || this.NodeType == XmlNodeType.Attribute) { FinishAttribute(); if (_RootCount > 0) { _CurrentToken = _ElementToken; } else { if (_PIToken != null && _DocTypeToken == null) { _CurrentToken = _PIToken; } else if(_DocTypeToken != null) { _CurrentToken = _DocTypeToken; } } _ReadCount = -1; return true; } return false; }
// All settings remain the same. /// <include file='doc\xmltextreader.uex' path='docs/doc[@for="XmlTextReader.ResetState"]/*' /> public void ResetState() { if (XmlNodeType.None != _PartialContentNodeType) { throw new InvalidOperationException(Res.GetString(Res.Xml_InvalidResetStateCall)); } if (ReadState.Initial == ReadState) { //noop. we are already at the begining of the document return; } _ReadState = ReadState.Initial; _RootCount = 0; ResetFieldsCollection(); _Scanner.Reset(); _NextFunction = _ParseRootIndex; _DtdParser = null; _TmpToken = new XmlNSElementTokenInfo(_Scanner, _NsMgr, XmlNodeType.None, String.Empty,-1, -1, -1, 0,false); _CurrentToken = _TmpToken; _CantHaveXmlDecl = false; _Encoding = _Scanner.Encoding; // // pop all the pushed elements // while (Pop() != null) ; }
/// <include file='doc\XmlTextReader.uex' path='docs/doc[@for="XmlTextReader.MoveToFirstAttribute"]/*' /> /// <devdoc> /// <para> /// Moves to the first attribute. /// </para> /// </devdoc> public override bool MoveToFirstAttribute() { if (GetAttributeCount() < 1) return false; FinishAttribute(); _ReadCount = 0; _CurrentToken = _Fields[_ReadCount]; return true; }
/// <include file='doc\XmlTextReader.uex' path='docs/doc[@for="XmlTextReader.MoveToNextAttribute"]/*' /> /// <devdoc> /// <para> /// Moves to the next attribute. /// </para> /// </devdoc> public override bool MoveToNextAttribute() { if ((_ReadCount+1) < GetAttributeCount()) { FinishAttribute(); _ReadCount++; _CurrentToken = _Fields[_ReadCount]; return true; } return false; }
// parse from root private void ParseRoot() { int LineNum = _Scanner.LineNum; int LinePos = _Scanner.LinePos; _LastToken = _Scanner.ScanContent(); switch (_LastToken) { case XmlToken.EOF: _ScannerEof = true; goto cleanup; case XmlToken.WHITESPACE: // // no matter what kind of whitespace, don't return any token // _CantHaveXmlDecl = true; if (!ReturnWhitespaceToken(_Scanner)) { _ContinueParsing = true; _CurrentToken = _WhitespaceToken; goto cleanup; } _WhitespaceToken.Depth = _ElementDepth+1 + _EntityDepthOffset; _CurrentToken = _WhitespaceToken; _CurrentToken.LineNum = LineNum; _CurrentToken.LinePos = LinePos; break; case XmlToken.NONE: // ok now we've reached the beginning of a tag int token = ParseTag(); switch (token) { case XmlToken.TAG: { _CantHaveXmlDecl = true; _RootCount++; } break; } break; default: throw new XmlException(Res.Xml_InvalidRootData, LineNum, LinePos); } cleanup: if (_RootCount > 1) { throw new XmlException(Res.Xml_MultipleRoots, LineNum, LinePos + 1); } }
/// <include file='doc\XmlTextReader.uex' path='docs/doc[@for="XmlTextReader.MoveToAttribute2"]/*' /> /// <devdoc> /// <para>Moves to the attribute with the specified index.</para> /// </devdoc> public override void MoveToAttribute(int i) { CheckIndexCondition(i); FinishAttribute(); _ReadCount = i; _CurrentToken = _Fields[_ReadCount]; }
// protected constructor, users should not be using this /// <include file='doc\XmlTextReader.uex' path='docs/doc[@for="XmlTextReader.XmlTextReader1"]/*' /> /// <internalonly/> /// <devdoc> /// <para>Initializes a new instance of the XmlTextReader class with the specified XmlNameTable.</para> /// </devdoc> protected XmlTextReader( XmlNameTable nt ) { // // internal variables // _ElementDepth = -1; _EntityDepthOffset = 0; _ReadCount = -1; // // variables for properties // _ReadState = ReadState.Initial; _NextState = 1; // // create interal components // _NameTable = nt; _ElementStack = new HWStack(STACK_INCREMENT); _ScannerStack = new HWStack(STACK_INCREMENT); // //create atom // _StringName = _NameTable.Add("String"); _MicrosoftSystemNamespace = _NameTable.Add("System"); _Decimal = _NameTable.Add("#decimal"); _Hex = _NameTable.Add("#hexidecimal"); _Amp = _NameTable.Add("amp"); _Lt = _NameTable.Add("lt"); _Gt = _NameTable.Add("gt"); _Quot = _NameTable.Add("quot"); _Apos = _NameTable.Add("apos"); _XmlNs = _NameTable.Add("xmlns"); _XmlSpaceAtom = _NameTable.Add("xml:space"); _XmlLangAtom = _NameTable.Add("xml:lang"); // //fields collection // _Used = -1; _MarkScannerCount = 10000; // _XmlSpace = XmlSpace.None; _XmlLang = String.Empty; _WhitespaceHandling = WhitespaceHandling.All; _XmlResolver = new XmlUrlResolver(); _CheckNamespaces = true; _TmpToken = new XmlNSElementTokenInfo(_Scanner, _NsMgr, XmlNodeType.None, String.Empty,-1, -1, -1, 0,false); _CurrentToken = _TmpToken; // PERF: these node types are not common therefore they // will only be constructed when used // _CommentToken = null; _CDATAToken = null; _DocTypeToken = null; _PIToken = null; _EndEntityToken = null; _NextFunction = _InitReader; _StringBuilder = new StringBuilder(100); }
// parse tag private int ParseTag() { int LineNum = _Scanner.LineNum; int LinePos = _Scanner.LinePos; int token = _Scanner.ScanMarkup(); switch (token) { case XmlToken.TAG: _NextFunction = _ParseElementIndex; _CantHaveXmlDecl = true; _ContinueParsing = true; break; case XmlToken.EOF: return XmlToken.EOF; case XmlToken.PI: { LinePos += 2; //To Skip markup <? if (_Scanner.IsToken("xml")) { // // if xml is declared, there should not be any token before this // if it is from ResolveEntity(), xml decl is allowed and should // not be returned // if (_CantHaveXmlDecl) throw new XmlException(Res.Xml_XmlDeclNotFirst, LineNum, LinePos); if (_PIToken == null) _PIToken = new XmlNameValueTokenInfo(_Scanner, _NsMgr, XmlNodeType.XmlDeclaration, -1, _Normalization); _PIToken.LineNum = LineNum; _PIToken.LinePos = LinePos; ParseXmlDecl(); if (_IsExternal) { _ContinueParsing = true; } else { _PIToken.Name = _NameTable.Add("xml"); _PIToken.SetValue(_StringBuilder); _PIToken.Depth = _ElementDepth + 1 + _EntityDepthOffset; _CurrentToken = _PIToken; } } else { bool hasBody = _Scanner.ScanPIName(); String name = _Scanner.GetTextAtom(); if (String.Compare(name, "xml", true, CultureInfo.InvariantCulture) == 0) throw new XmlException(Res.Xml_InvalidPIName, name, LineNum, LinePos); if (_CheckNamespaces && _Scanner.Colon() != -1) throw new XmlException(Res.Xml_InvalidPIName, name, LineNum, LinePos); if (_PIToken == null) _PIToken = new XmlNameValueTokenInfo(_Scanner, _NsMgr, XmlNodeType.ProcessingInstruction, -1, _Normalization); _CantHaveXmlDecl = true; _PIToken.Name = name; _PIToken.NodeType = XmlNodeType.ProcessingInstruction; if (hasBody) { _Scanner.ScanPI(); _PIToken.SetValue(_Scanner, null, _Scanner.StartPos, _Scanner.TextLength); } else { _PIToken.Value = String.Empty; } _PIToken.Depth = _ElementDepth + 1 + _EntityDepthOffset; _CurrentToken = _PIToken; _Scanner.Advance(2); } } break; case XmlToken.COMMENT: LinePos += 4; //To Skip markup <!-- if (_CommentToken == null) _CommentToken = new XmlValueTokenInfo(_Scanner, _NsMgr, XmlNodeType.Comment, -1, _Normalization); _CantHaveXmlDecl = true; _CommentToken.SetValue(_Scanner, null, _Scanner.StartPos, _Scanner.TextLength); _CommentToken.Depth = _ElementDepth + 1 + _EntityDepthOffset; _CurrentToken = _CommentToken; _Scanner.Advance(3); break; case XmlToken.CDATA: _CantHaveXmlDecl = true; LinePos += 9; //To skip the Markup <![CDATA[ if ((XmlNodeType.Document == _PartialContentNodeType || XmlNodeType.None == _PartialContentNodeType) && (_ElementStack.Length < 1 || _RootCount < 1)) throw new XmlException(Res.Xml_InvalidRootData, LineNum, LinePos); if (_CDATAToken == null) _CDATAToken = new XmlValueTokenInfo(_Scanner, _NsMgr, XmlNodeType.CDATA, -1, _Normalization); _CDATAToken.SetValue(_Scanner, null, _Scanner.StartPos, _Scanner.TextLength); _CDATAToken.Depth = _ElementDepth + 1 + _EntityDepthOffset; _CurrentToken = _CDATAToken; _Scanner.Advance(3); break; case XmlToken.DECL: { if (_DtdParser != null) { //A document cant have multiple doctyp throw new XmlException(Res.Xml_MultipleDTDsProvided, LineNum, LinePos); } if (_RootCount > 0) { throw new XmlException(Res.Xml_BadDTDLocation, LineNum, LinePos); } int startPos = _Scanner.CurrentPos-2; _Scanner.ReadBufferConsistency = _Scanner.StartPos; if (_DocTypeToken == null) _DocTypeToken = new XmlDtdTokenInfo(_Scanner, _NsMgr, XmlNodeType.DocumentType, -1, _Normalization); _CantHaveXmlDecl = true; _Used = -1; _DocTypeToken.Name = ParseDtd( _Scanner ); if (_DtdParser != null) { LinePos = _DtdParser.DTDNameStartPosition; LineNum = _DtdParser.DTDNameStartLine; } if (!_BufferConsistency) _Scanner.ReadBufferConsistency = -1; _DocTypeToken._DtdParser = _DtdParser; _DocTypeToken.Depth = _ElementDepth + 1 + _EntityDepthOffset; _CurrentToken = _DocTypeToken; } break; case XmlToken.ENDTAG: { LinePos += 2; //to skip the markup </ _Scanner.ScanNameWOCharChecking(); if (_LastElementInfo == null) { throw new XmlException(Res.Xml_UnexpectedEndTag, LineNum, LinePos); } int count = _Scanner.TextLength; char[] scannerbuff = _Scanner.InternalBuffer; if(_LastElementInfo._NameWPrefix.Length != count) { // The length of the start tag and end tag should be the same. // If it is not, no need to check char by char. goto errorCase; } int scannerOffset = _Scanner.TextOffset; for (int i = scannerOffset, j = 0; i < (scannerOffset + count) && j < count; i++, j++) { if (_LastElementInfo._NameWPrefix[j] != scannerbuff[i]) { goto errorCase; } } // // begin and end tag has to come from the same scanner // if (_LastElementInfo._Scanner != _Scanner) { throw new XmlException(Res.Xml_TagNotInTheSameEntity, _LastElementInfo._NameWPrefix, LineNum, LinePos); } _EndElementToken.SetName(_LastElementInfo._NameWPrefix, _LastElementInfo._LocalName, _LastElementInfo._Prefix, _LastElementInfo._NS, _ElementDepth + _EntityDepthOffset, _Scanner); _CurrentEndElementStart = _Scanner.StartPos-2; ReadEndElementToken(); _Scanner.ScanToken(XmlToken.TAGEND); // skip whitespace to the '>' _CurrentEndElementEnd = _Scanner.CurrentPos; _ElementDepth--; } break; } _CurrentToken.LineNum = LineNum; _CurrentToken.LinePos = LinePos; return token; errorCase: String[] args; string exceptionCode; if (String.Empty != _BaseURI) { args = new String[4]; args[3] = _BaseURI; exceptionCode = Res.Xml_TagMismatchFileName; } else { args = new String[3]; exceptionCode = Res.Xml_TagMismatch; } args[0] = _LastElementInfo._NameWPrefix; args[1] = _LastElementInfo._LineNumber.ToString(); args[2] = _Scanner.GetText(); throw new XmlException(exceptionCode, args, LineNum, LinePos); }
private void ReadEndElementToken() { _EndElementToken.NodeType = XmlNodeType.EndElement; _CurrentToken = _EndElementToken; _NextFunction = _PopEndElementIndex; }
private void ReadEndEntity() { ScannerInfo scanner = (ScannerInfo)_ScannerStack.Peek(); if (_EndEntityToken == null) _EndEntityToken = new XmlNameValueTokenInfo(_Scanner, _NsMgr, XmlNodeType.EndEntity, -1, String.Empty, false); _CurrentToken = _EndEntityToken; _EndEntityToken.Name = scanner._EntityName; _EndEntityToken.LineNum = _Scanner.LineNum; _EndEntityToken.LinePos = _Scanner.LinePos; _EndEntityToken.Depth = scanner._EntityDepth; }
/// <include file='doc\XmlTextReader.uex' path='docs/doc[@for="XmlTextReader.ResetToCloseState"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> internal void ResetToCloseState() { // // reset properties state // _TmpToken.NameWPrefix = String.Empty; _TmpToken.Name = String.Empty; _TmpToken.Prefix = String.Empty; _TmpToken.Namespaces = String.Empty; _TmpToken.LinePos = (null == _Scanner ? 0 : _Scanner.LinePos); //0; _TmpToken.LineNum = (null == _Scanner ? 0 : _Scanner.LineNum); //0; _CurrentToken = _TmpToken; _XmlSpace = XmlSpace.None; _XmlLang = String.Empty; }
private void ReadEmptyText() { if (_CurrentToken.IsAttributeText) { _AttributeTextToken.Depth = _CurrentToken.Depth+1; _AttributeTextToken.Value = String.Empty; _AttributeTextToken.QuoteChar = _CurrentToken.QuoteChar; _CurrentToken = _AttributeTextToken; } else { _TextToken.Depth = _CurrentToken.Depth+1; _TextToken.Value = String.Empty; _CurrentToken = _TextToken; _CurrentToken.LineNum = 1; _CurrentToken.LinePos = 1; } // // if we are emitting this token because there is no other token // the next token, we need to go is endEntity // if (this.NodeType == XmlNodeType.EntityReference) { _NextFunction = _ReadEndEntityIndex; _ContinueParsing = true; return; } if (_ElementToken.IsEmpty) _NextFunction = _PopEndElementIndex; else _NextFunction = _ParseBeginTagIndex; }
// // only come here when EntityHandling.ExpandCharEntities // private void ParseBeginTagExpandCharEntities() { XmlNodeType nodeType = XmlNodeType.Text; String name = String.Empty, dataType = String.Empty; // 1: text token, 2: whitespace token int hasToken = 0; int erPos = -1; int oldElementDepth = _ElementDepth; char ch='\0'; bool originalCantHaveXmlDecl = _CantHaveXmlDecl; _CantHaveXmlDecl = true; _StringBuilder.Length = 0; int LineNum = _Scanner.LineNum; int LinePos = _Scanner.LinePos; do { switch (_NextState) { case 1: if (_ElementStack.Length < 1 && (XmlNodeType.Document == _PartialContentNodeType || XmlNodeType.None == _PartialContentNodeType )) { _NextFunction = _ParseRootIndex; _ContinueParsing = true; _NextState = 1; goto cleanup; } _NextState = 2; if (!_BufferConsistency) _Scanner.ReadBufferConsistency = -1; goto case 2; case 2: erPos = _Scanner.CurrentPos; _LastToken = _Scanner.ScanContent(); _Scanner.ReadBufferConsistency = _Scanner.StartPos; switch (_LastToken) { case XmlToken.NONE: if (XmlNodeType.Attribute == _PartialContentNodeType) { //there shouldnt be any '<' char while processing attribute value throw new XmlException(Res.Xml_InvalidCharacter, XmlException.BuildCharExceptionStr('<'), _Scanner.LineNum, _Scanner.LinePos); } _NextState = 12; switch (hasToken) { case 1: goto seeToken; case 2: _NextState =11; break; } break; case XmlToken.EOF: _NextState = 1; _ScannerEof = true; switch(hasToken) { case 0 : _NextState = 1; goto cleanup; case 1 : if (XmlNodeType.Attribute == _PartialContentNodeType || XmlNodeType.Element == _PartialContentNodeType) { // The only way we could have gotten to this point is if someone wanted to parse the // following valid Mixed Element content "<foo>bar</foo>some more text" // If we don't do this, we will eat up the last token _ScannerEof = false; _NextFunction = _FragmentTrailingTextNode; } goto seeToken; case 2: if (XmlNodeType.Attribute == _PartialContentNodeType || XmlNodeType.Element == _PartialContentNodeType) { // The only way we could have gotten to this point is if someone wanted to parse the // following valid Mixed Element content "<foo>bar</foo>some more text" // If we don't do this, we will eat up the last token _ScannerEof = false; _NextFunction = _FragmentTrailingTextNode; } _NextState = 11; break; } oldElementDepth = _ElementDepth; break; case XmlToken.ENDQUOTE: _NextState = 1; goto cleanup; case XmlToken.WHITESPACE: if (hasToken == 0) hasToken = 2; _StringBuilder.Append(_Scanner.InternalBuffer, _Scanner.TextOffset, _Scanner.TextLength); break; case XmlToken.TEXT: hasToken = 1; _StringBuilder.Append(_Scanner.InternalBuffer, _Scanner.TextOffset, _Scanner.TextLength); nodeType = XmlNodeType.Text; _NextState = 2; break; case XmlToken.ENTITYREF: ch = _Scanner.ScanNamedEntity(); // // 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, LinePos + 1); if (ch != 0) { hasToken = 1; _StringBuilder.Append(ch); dataType = "Char"; _Scanner.Advance(); _NextState = 2; // // only if build in entity needs to be return as its own // nodeType = XmlNodeType.Text; name = String.Empty; break; } switch (hasToken) { case 1: // First return the text we have up to this point. _Scanner.CurrentPos = erPos; _NextState = 2; name = String.Empty; goto seeToken; case 2: // already an whitespace token _Scanner.CurrentPos = erPos; _NextState = 9; name = String.Empty; break; default: // Return the entity reference as a node. name = _Scanner.GetTextAtom(); nodeType = XmlNodeType.EntityReference; LinePos = _Scanner.LinePos - name.Length; _NextState = 10; break; } break; case XmlToken.NUMENTREF: hasToken = 1; _StringBuilder.Append(_Scanner.ScanDecEntity()); nodeType = XmlNodeType.Text; _NextState = 2; break; case XmlToken.HEXENTREF: char[] chArray = _Scanner.ScanHexEntity(); if (1 == chArray.Length && (chArray[0] == 0x0020 || chArray[0] == 0xD || chArray[0] == 0xA || chArray[0] == (char)0x9)) { // we might have already seen a text node before this and should not chang the node type here if that is true if (hasToken == 0) { // We have a whitespace node. This should be reported as such. nodeType = XmlNodeType.Whitespace; hasToken = 2; } } else { nodeType = XmlNodeType.Text; hasToken = 1; } _StringBuilder.Append(chArray); _NextState = 2; break; default: throw new XmlException(Res.Xml_InternalError); } break; case 9: // whitespace token handling _NextState = 2; hasToken =0; if (!ReturnWhitespaceToken(_StringBuilder)) { _CurrentToken = _WhitespaceToken; _NextState = 2; break; } _WhitespaceToken.Depth = oldElementDepth + 1 + _EntityDepthOffset; _CurrentToken = _WhitespaceToken; goto otherToken; case 10: _Scanner.Advance(); hasToken = 1; _NextState = 2; // general entity special case _ERToken.NodeType = nodeType; _ERToken.Name = name; _ERToken.Depth = oldElementDepth +1 + _EntityDepthOffset; _CurrentToken = _ERToken; goto otherToken; case 11: // whitespace token handling, there is no more _NextState = 2; hasToken =0; if (!ReturnWhitespaceToken(_StringBuilder)) { _CurrentToken = _WhitespaceToken; _ContinueParsing = true; goto cleanup; } _WhitespaceToken.Depth = oldElementDepth + 1 + _EntityDepthOffset; _CurrentToken = _WhitespaceToken; goto otherToken; case 12: _NextState = 1; _CantHaveXmlDecl = originalCantHaveXmlDecl; ParseTag(); goto cleanup; default: Debug.Assert(false, "unknown state within ParseBeginTag()"); break; } } while (true); seeToken: _TextToken.SetValue(_StringBuilder); _TextToken.SetTokenInfo(nodeType, name, oldElementDepth +1 + _EntityDepthOffset); _CurrentToken = _TextToken; otherToken: _CurrentToken.LineNum = LineNum; _CurrentToken.LinePos = LinePos; cleanup: if (!_BufferConsistency) _Scanner.ReadBufferConsistency = -1; return; }
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; }
/// <include file='doc\XmlTextReader.uex' path='docs/doc[@for="XmlTextReader.MoveToAttribute"]/*' /> /// <devdoc> /// <para>Moves to the attribute with the specified name.</para> /// </devdoc> public override bool MoveToAttribute(string name) { int ordinal; if (GetOrdinal(name, out ordinal)) { FinishAttribute(); _ReadCount = ordinal; _CurrentToken = _Fields[_ReadCount]; return true; } else { return false; } }
private void Init() { if (_Scanner == null) { CreateScanner(); } _Scanner.Normalization = Normalization; _Scanner.NamespaceSupport = _CheckNamespaces; if (_Encoding == null) { _Encoding = _Scanner.Encoding; } _TextToken = new XmlWSTokenInfo(_Scanner, _NsMgr, XmlNodeType.Text, -1, _Normalization); _WhitespaceToken = new XmlWSTokenInfo(_Scanner, _NsMgr, XmlNodeType.Whitespace, -1, _Normalization); _ERToken = new XmlNameValueTokenInfo(_Scanner, _NsMgr, XmlNodeType.EntityReference, -1, String.Empty, false); if (_CheckNamespaces) { _TmpToken = new XmlNSElementTokenInfo(_Scanner, _NsMgr, XmlNodeType.None, String.Empty,-1, -1, -1, 0,false); _ElementToken = new XmlNSElementTokenInfo(_Scanner, _NsMgr, XmlNodeType.Element, String.Empty,-1, -1, -1, -1,false); _EndElementToken = new XmlNSElementTokenInfo(_Scanner, _NsMgr, XmlNodeType.EndElement, String.Empty,-1, -1, -1, -1,false); _AttributeTextToken = new XmlNSAttributeTokenInfo(_Scanner, _NsMgr, XmlNodeType.Text, _Normalization, _XmlNs); } else { _TmpToken = new XmlElementTokenInfo(_Scanner, _NsMgr, XmlNodeType.None, String.Empty,-1, -1, -1, 0, false); _ElementToken = new XmlElementTokenInfo(_Scanner, _NsMgr, XmlNodeType.Element, String.Empty,-1, -1, -1, -1, false); _EndElementToken = new XmlElementTokenInfo(_Scanner, _NsMgr, XmlNodeType.Element, String.Empty,-1, -1, -1, -1, false); _AttributeTextToken = new XmlAttributeTokenInfo(_Scanner, _NsMgr, XmlNodeType.Text, _Normalization); } _CurrentToken = _TmpToken; }
/// <include file='doc\XmlTextReader.uex' path='docs/doc[@for="XmlTextReader.MoveToAttribute1"]/*' /> /// <devdoc> /// <para>Moves to the attribute with the specified name and namespace.</para> /// </devdoc> public override bool MoveToAttribute(string localName, string namespaceURI) { int ordinal; if (namespaceURI == null) namespaceURI = String.Empty; if (GetOrdinal(localName, namespaceURI, out ordinal)) { _ReadCount = ordinal; FinishAttribute(); _CurrentToken = _Fields[_ReadCount]; return true; } else { return false; } }
// // parse element // private void SetElementValues() { _Scanner.ScanToken(XmlToken.NAME); int offset = _Scanner.StartPos; if (_Scanner.GetChar(offset -1) != '<') throw new XmlException(Res.Xml_UnexpectedToken, XmlToken.ToString(XmlToken.NAME), _Scanner.LineNum, _Scanner.LinePos - 1); // // increment the element depth // _ElementDepth++; // // setup Record value // _ElementToken.SetName(_Scanner, offset, _Scanner.TextLength, _Scanner.Colon(), _ElementDepth + _EntityDepthOffset); // // the rest of the dynamic values // _CurrentToken = _ElementToken; _CurrentElementStart = _Scanner.StartPos-1; }
// 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; }