System.Xml.XmlReader.ReadToDescendant C# (CSharp) Méthode

ReadToDescendant() public méthode

public ReadToDescendant ( string name ) : bool
name string
Résultat bool
        public virtual bool ReadToDescendant(string name)
        {
            if (name == null || name.Length == 0)
            {
                throw XmlConvert.CreateInvalidNameArgumentException(name, nameof(name));
            }
            // save the element or root depth
            int parentDepth = Depth;
            if (NodeType != XmlNodeType.Element)
            {
                // adjust the depth if we are on root node
                if (ReadState == ReadState.Initial)
                {
                    Debug.Assert(parentDepth == 0);
                    parentDepth--;
                }
                else
                {
                    return false;
                }
            }
            else if (IsEmptyElement)
            {
                return false;
            }

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

            // find the descendant
            while (Read() && Depth > parentDepth)
            {
                if (NodeType == XmlNodeType.Element && Ref.Equal(name, Name))
                {
                    return true;
                }
            }
            Debug.Assert(NodeType == XmlNodeType.EndElement || NodeType == XmlNodeType.None || ReadState == ReadState.Error);
            return false;
        }

Same methods

XmlReader::ReadToDescendant ( string localName, string namespaceURI ) : bool

Usage Example

Exemple #1
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("ContainerElement") == false)
            {
                throw new MyException("could not find the start of element ContainerElement");
            }

            int depth = reader.Depth;

            reader.ReadToDescendant("xx1:containee");
            reader.ReadToNextSibling("xx2", "Containee2");
            reader.ReadToNextSibling("Containee3");

            // moved to closing ContainerElement
            while (reader.Depth > depth && reader.Read())
            {
            }
            int       counter      = 0;
            const int NODES_AT_END = 1;

            while (reader.Read())
            {
                counter++;
            }
            if (counter != NODES_AT_END)
            {
                throw new MyException(String.Format("expected {0} nodes, but found {1}", NODES_AT_END, counter));
            }
        }
All Usage Examples Of System.Xml.XmlReader::ReadToDescendant