Exemplo n.º 1
0
 // Moves to the next attribute.
 public override bool MoveToNextAttribute()
 {
     if (_currentAttrIndex + 1 < _attributeCount)
     {
         _cachedNode = _attributeEvents[++_currentAttrIndex];
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
 // Moves to the attribute with the specified index.
 public override void MoveToAttribute(int i)
 {
     if (i < 0 || i >= _attributeCount)
     {
         throw new ArgumentOutOfRangeException(nameof(i));
     }
     _currentAttrIndex = i;
     _cachedNode       = _attributeEvents[i];
 }
Exemplo n.º 3
0
 // Moves to the first attribute.
 public override bool MoveToFirstAttribute()
 {
     if (_attributeCount == 0)
     {
         return(false);
     }
     _currentAttrIndex = 0;
     _cachedNode       = _attributeEvents[0];
     return(true);
 }
Exemplo n.º 4
0
 private void Init()
 {
     _coreReaderNameTable = _coreReader.NameTable;
     _cacheState          = CachingReaderState.Init;
     _contentIndex        = 0;
     _currentAttrIndex    = -1;
     _currentContentIndex = -1;
     _attributeCount      = 0;
     _cachedNode          = null;
     _readAhead           = false;
     //Initialize the cachingReader with start state
     if (_coreReader.NodeType == XmlNodeType.Element)
     {
         ValidatingReaderNodeData element = AddContent(_coreReader.NodeType);
         element.SetItemData(_coreReader.LocalName, _coreReader.Prefix, _coreReader.NamespaceURI, _coreReader.Depth);  //Only created for element node type
         element.SetLineInfo(_lineInfo);
         RecordAttributes();
     }
 }
Exemplo n.º 5
0
        // Moves to the attribute with the specified LocalName and NamespaceURI
        public override bool MoveToAttribute(string name, string?ns)
        {
            ns = (ns == null) ? string.Empty : _coreReaderNameTable.Get(ns);
            string?atomizedName = _coreReaderNameTable.Get(name);
            ValidatingReaderNodeData attribute;

            for (int i = 0; i < _attributeCount; i++)
            {
                attribute = _attributeEvents[i];
                if (Ref.Equal(attribute.LocalName, atomizedName) &&
                    Ref.Equal(attribute.Namespace, ns))
                {
                    _currentAttrIndex = i;
                    _cachedNode       = _attributeEvents[i];
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        // Moves to the attribute with the specified Name.
        public override bool MoveToAttribute(string name)
        {
            int i;

            if (!name.Contains(':'))
            {
                i = GetAttributeIndexWithoutPrefix(name);
            }
            else
            {
                i = GetAttributeIndexWithPrefix(name);
            }

            if (i >= 0)
            {
                _currentAttrIndex = i;
                _cachedNode       = _attributeEvents[i];
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        // Reads the next node from the stream/TextReader.
        public override bool Read()
        {
            switch (_cacheState)
            {
            case CachingReaderState.Init:
                _cacheState = CachingReaderState.Record;
                goto case CachingReaderState.Record;

            case CachingReaderState.Record:
                ValidatingReaderNodeData?recordedNode = null;
                if (_coreReader.Read())
                {
                    switch (_coreReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        //Dont record element within the content of a union type since the main reader will break on this and the underlying coreReader will be positioned on this node
                        _cacheState = CachingReaderState.ReaderClosed;
                        return(false);

                    case XmlNodeType.EndElement:
                        recordedNode = AddContent(_coreReader.NodeType);
                        recordedNode.SetItemData(_coreReader.LocalName, _coreReader.Prefix, _coreReader.NamespaceURI, _coreReader.Depth);          //Only created for element node type
                        recordedNode.SetLineInfo(_lineInfo);
                        break;

                    case XmlNodeType.Comment:
                    case XmlNodeType.ProcessingInstruction:
                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        recordedNode = AddContent(_coreReader.NodeType);
                        recordedNode.SetItemData(_coreReader.Value);
                        recordedNode.SetLineInfo(_lineInfo);
                        recordedNode.Depth = _coreReader.Depth;
                        break;

                    default:
                        break;
                    }
                    _cachedNode = recordedNode;
                    return(true);
                }
                else
                {
                    _cacheState = CachingReaderState.ReaderClosed;
                    return(false);
                }

            case CachingReaderState.Replay:
                if (_currentContentIndex >= _contentIndex)
                {     //When positioned on the last cached node, switch back as the underlying coreReader is still positioned on this node
                    _cacheState = CachingReaderState.ReaderClosed;
                    _cacheHandler(this);
                    if (_coreReader.NodeType != XmlNodeType.Element || _readAhead)
                    {     //Only when coreReader not positioned on Element node, read ahead, otherwise it is on the next element node already, since this was not cached
                        return(_coreReader.Read());
                    }
                    return(true);
                }
                _cachedNode = _contentEvents[_currentContentIndex];
                if (_currentContentIndex > 0)
                {
                    ClearAttributesInfo();
                }
                _currentContentIndex++;
                return(true);

            default:
                return(false);
            }
        }