Пример #1
0
        public bool Read()
        {
            _currentValues = null;

            if (_eof)
            {
                return(false);
            }

            if (!_xmlReader.Read())
            {
                _eof = true;
                return(false);
            }

            do
            {
                if (_xmlReader.NodeType == XmlNodeType.Element)
                {
                    var level = _currentLevel + 1;

                    if (!_xmlReader.IsEmptyElement)
                    {
                        _currentLevel++;
                    }

                    if (level != _dataElementPathItemIndex)
                    {
                        throw new FormatException(string.Format(Properties.Resources.XmlReaderExpectedElement, _dataElementName, _xmlReader.LocalName));
                    }

                    if (XmlNameComparer.IsEqualElementNames(_xmlReader.LocalName, _dataElementName))
                    {
                        _currentValues = new string[this.FieldCount];
                        ReadItemAttributes();
                        _itemCount++;

                        return(true);
                    }
                }
                else if (_xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    if (_currentLevel < _dataElementPathItemIndex)
                    {
                        _eof = true;
                        return(false);
                    }

                    _currentLevel--;
                }
            } while (_xmlReader.Read());

            return(false);
        }
Пример #2
0
        private int GetIndex(string name)
        {
            for (var i = 0; i < _fields.Length; i++)
            {
                if (XmlNameComparer.IsEqualElementNames(_fields[i], name))
                {
                    return(i);
                }
            }

            return(-1);
        }
Пример #3
0
        private void MoveToDataElement()
        {
            var parentElementPathItemIndex = _dataElementPathItems.Length - 2;

            if (parentElementPathItemIndex < 0)
            {
                return;
            }

            var elements = new Stack <string>();
            var found    = false;

            while (_xmlReader.Read())
            {
                if (_xmlReader.NodeType == XmlNodeType.Element)
                {
                    if (!_xmlReader.IsEmptyElement)
                    {
                        _currentLevel++;
                        elements.Push(_xmlReader.LocalName);

                        if (_currentLevel < _dataElementPathItems.Length)
                        {
                            if (XmlNameComparer.IsEqualElementNames(_xmlReader.LocalName, _dataElementPathItems[_currentLevel]))
                            {
                                if (_currentLevel == parentElementPathItemIndex)
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (_xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    var name = elements.Pop();
                    _currentLevel--;

                    if (!XmlNameComparer.IsEqualElementNames(name, _xmlReader.LocalName))
                    {
                        throw new FormatException(string.Format(Properties.Resources.XmlReaderExpectedClosingTag, name, _xmlReader.LocalName));
                    }
                }
            }

            if (!found)
            {
                throw new FormatException(string.Format(Properties.Resources.XmlReaderElementNotFound, _dataElementPath));
            }
        }