Example #1
0
        // Reads to the next sibling of the current element with the given LocalName and NamespaceURI.
        public virtual bool ReadToNextSibling(string localName, string namespaceURI)
        {
            if (localName == null || localName.Length == 0)
            {
                throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, "localName");
            }

            if (namespaceURI == null)
            {
                throw new ArgumentNullException("namespaceURI");
            }

            // atomize local name and namespace
            localName    = this.NameTable.Add(localName);
            namespaceURI = this.NameTable.Add(namespaceURI);

            // find the next sibling
            XmlNodeType nt;

            do
            {
                this.SkipSubtree();
                nt = this.NodeType;
                if (nt == XmlNodeType.Element && Ref.Equal(localName, this.LocalName) && Ref.Equal(namespaceURI, this.NamespaceURI))
                {
                    return(true);
                }
            } while (nt != XmlNodeType.EndElement && !this.EOF);
            return(false);
        }
Example #2
0
        // Reads to the following element with the given LocalName and NamespaceURI.
        public virtual bool ReadToFollowing(string localName, string namespaceURI)
        {
            if (localName == null || localName.Length == 0)
            {
                throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, "localName");
            }

            if (namespaceURI == null)
            {
                throw new ArgumentNullException("namespaceURI");
            }

            // atomize local name and namespace
            localName    = this.NameTable.Add(localName);
            namespaceURI = this.NameTable.Add(namespaceURI);

            // find following element with that name
            while (this.Read())
            {
                if (this.NodeType == XmlNodeType.Element && Ref.Equal(localName, this.LocalName) && Ref.Equal(namespaceURI, this.NamespaceURI))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        // Reads to the first descendant of the current element with the given LocalName and NamespaceURI.
        public virtual bool ReadToDescendant(string localName, string namespaceURI)
        {
            if (localName == null || localName.Length == 0)
            {
                throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, "localName");
            }

            if (namespaceURI == null)
            {
                throw new ArgumentNullException("namespaceURI");
            }

            // save the element or root depth
            var parentDepth = this.Depth;

            if (this.NodeType != XmlNodeType.Element)
            {
                // adjust the depth if we are on root node
                if (this.ReadState == ReadState.Initial)
                {
                    Debug.Assert(parentDepth == 0);
                    parentDepth--;
                }
                else
                {
                    return(false);
                }
            }
            else if (this.IsEmptyElement)
            {
                return(false);
            }

            // atomize local name and namespace
            localName    = this.NameTable.Add(localName);
            namespaceURI = this.NameTable.Add(namespaceURI);

            // find the descendant
            while (this.Read() && this.Depth > parentDepth)
            {
                if (this.NodeType == XmlNodeType.Element && Ref.Equal(localName, this.LocalName) && Ref.Equal(namespaceURI, this.NamespaceURI))
                {
                    return(true);
                }
            }

            Debug.Assert(this.NodeType == XmlNodeType.EndElement || (parentDepth == -1 && this.ReadState == ReadState.EndOfFile));
            return(false);
        }
Example #4
0
        // Reads to the following element with the given Name.
        public virtual bool ReadToFollowing(string name)
        {
            if (name == null || name.Length == 0)
            {
                throw XmlExceptionHelper.CreateInvalidNameArgumentException(name, "name");
            }

            // atomize name
            name = this.NameTable.Add(name);

            // find following element with that name
            while (this.Read())
            {
                if (this.NodeType == XmlNodeType.Element && Ref.Equal(name, this.Name))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #5
0
        internal void CheckElement(string localName, string namespaceURI)
        {
            if (localName == null || localName.Length == 0)
            {
                throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, "localName");
            }

            if (namespaceURI == null)
            {
                throw new ArgumentNullException("namespaceURI");
            }

            if (this.NodeType != XmlNodeType.Element)
            {
                throw new XmlException(Res.Xml_InvalidNodeType, this.NodeType.ToString(), this as IXmlLineInfo);
            }

            if (this.LocalName != localName || this.NamespaceURI != namespaceURI)
            {
                throw new XmlException(Res.Xml_ElementNotFoundNs, new string[2] {
                    localName, namespaceURI
                }, this as IXmlLineInfo);
            }
        }
Example #6
0
        // Reads to the next sibling of the current element with the given Name.
        public virtual bool ReadToNextSibling(string name)
        {
            if (name == null || name.Length == 0)
            {
                throw XmlExceptionHelper.CreateInvalidNameArgumentException(name, "name");
            }

            // atomize name
            name = this.NameTable.Add(name);

            // find the next sibling
            XmlNodeType nt;

            do
            {
                this.SkipSubtree();
                nt = this.NodeType;
                if (nt == XmlNodeType.Element && Ref.Equal(name, this.Name))
                {
                    return(true);
                }
            } while (nt != XmlNodeType.EndElement && !this.EOF);
            return(false);
        }