public OldParserSynchronizer(EnhancedXmlParser enhancedXmlParser, IXmlTagParsingStrategy parsingStrategy, XmlParser oldParser) { this.enhancedXmlParser = enhancedXmlParser; this.oldParser = oldParser; this.parsingStrategy = parsingStrategy; enhancedXmlParser.MoveOldParserToCurrentTag(oldParser); }
public bool MoveToCurrentTagOfOldParser(XmlParser oldParser, IXmlTagParsingStrategy parsingStrategy) { Debug.Assert(CurrentPosition <= oldParser.getCurrIndex()); RefreshDataFromOldParser(oldParser); var currentTag = oldParser.getNextTag(); while (CurrentPosition < oldParser.getCurrIndex()) { if (!MoveToNextTag(parsingStrategy)) { return(false); } } if ((CurrentTagName == currentTag) || (CurrentTagName == currentTag.Substring(1))) { suppressNextMove = true; return(true); } return(false); }
public bool MoveToNextTag(IXmlTagParsingStrategy tagParsingStrategy) { if (IsOnEndOfElementBoundary) { return(false); } if (suppressNextMove) { suppressNextMove = false; return(true); } return(CurrentState.MoveToNextTag(tagParsingStrategy)); }
/// <summary> /// Moves the parser to the next tag. If the operation succeeded - which means that the parser's /// cursor was moved to a valid tag, the method returns true. Otherwise, it returns false, in which /// case the parser is invalidated and cannot be used until Reset() is called. /// </summary> /// <returns>The method returns true if the tags parser was actually moved to another tag and is in valid state. /// Otherwise, the method returns false.</returns> public bool MoveToNextTag(IXmlTagParsingStrategy parsingStrategy) { Validate(); int nextTagStartPosition; if (!FindNextTag(Cursor.EndPosition, out nextTagStartPosition)) { // No tag start. return(Invalidate()); } _cursor.StartPosition = nextTagStartPosition; return(UpdateState(parsingStrategy)); }
public IDisposable SwitchToOldParser(XmlParser oldParser, IXmlTagParsingStrategy parsingStrategy) { oldParser.setXMLdata(CurrentState.XmlData); return(new OldParserSynchronizer(this, parsingStrategy, oldParser)); }
/// <summary> /// Updates the current state after a successful move. /// </summary> /// <returns>Return whether the parser is still in valid state (true) or not (false).</returns> bool UpdateState(IXmlTagParsingStrategy parsingStrategy) { // Find the end of the current tag. if (!parsingStrategy.FindEndOfTag(_xml, _cursor)) { // Tag is not closed. return(Invalidate()); } // Fit cursor to exact tag boundaries. while (_cursor.EndPosition > _cursor.StartPosition && _xml[_cursor.EndPosition - 1] != '>') { _cursor.EndPosition--; } if (_cursor.EndPosition <= _cursor.StartPosition) { return(Invalidate()); } XmlParserTagInfo currentTag = Current; if (currentTag != XmlParserTagInfo.NullTag && !(currentTag.IsEmptyElement || currentTag.IsElementClosingTag)) { _path.Append(currentTag); } bool isElementClosingTag = false; bool isEmptyElement = false; // Determine whether the current tag is an element closing tag. if (IsClosingTag(Cursor.StartPosition)) { isElementClosingTag = true; } else { // Determine whether the current element is empty (no children). if (_xml[Cursor.EndPosition - 2] == '/') { isEmptyElement = true; } } string currentTagName; if (!GetTagName(Cursor.StartPosition, out currentTagName)) { return(Invalidate()); } currentTag = new XmlParserTagInfo(_cursor, currentTagName); currentTag.IsEmptyElement = isEmptyElement; currentTag.IsElementClosingTag = isElementClosingTag; Current = currentTag; if (isElementClosingTag) { XmlParserTagInfo tag = _path.RemoveLastEntry(); Debug.Assert(tag.Name == currentTagName, "Popped tag name '" + tag.Name + "' is not as expected: '" + currentTagName + "'"); Current.IsBoundaryElement = tag.IsBoundaryElement; } return(true); }