コード例 #1
0
ファイル: XmlReader.cs プロジェクト: yisea123/NETMF-LPC
        /// <summary>
        /// Checks that the LocalName and NamespaceURI properties of the element found
        /// matches the given strings before reading a text-only element.
        /// </summary>
        /// <param name="localname">The local name of the element.</param>
        /// <param name="ns">The namespace URI of the element.</param>
        /// <returns>The text contained in the element that was read. An empty string
        /// if the element is empty (&lt;item&gt;&lt;/item&gt; or &lt;item/&gt;).</returns>
        public virtual string ReadElementString(string localname, string ns)
        {
            string result = "";

            if (MoveToContent() != XmlNodeType.Element)
            {
                throw new XmlException(XmlException.XmlExceptionErrorCode.InvalidNodeType);
            }

            XmlReader_XmlNode node = (XmlReader_XmlNode)_xmlNodes.Peek();

            if (!StringRefEquals(node.LocalName, localname) ||
                !StringRefEquals(node.NamespaceURI, ns))
            {
                throw new XmlException(XmlException.XmlExceptionErrorCode.ElementNotFound);
            }

            if (!_isEmptyElement)
            {
                result = ReadString();
                if (_nodeType != XmlNodeType.EndElement)
                {
                    throw new XmlException(XmlException.XmlExceptionErrorCode.InvalidNodeType);
                }
            }

            Read(); // read the EndElement or the empty StartElement

            return(result);
        }
コード例 #2
0
ファイル: XmlReader.cs プロジェクト: yisea123/NETMF-LPC
        /// <summary>
        /// Calls MoveToContent and tests if the current content node is a start tag or
        /// empty element tag and if the LocalName and NamespaceURI properties of the
        /// element found match the given strings.
        /// </summary>
        /// <param name="localname">The local name of the element.</param>
        /// <param name="ns">The namespace URI of the element.</param>
        /// <returns>true if the resulting node is an element. false if a node type other
        /// than XmlNodeType.Element was found or if the LocalName and NamespaceURI
        /// properties of the element do not match the specified strings.</returns>
        public virtual bool IsStartElement(string localname, string ns)
        {
            if (MoveToContent() == XmlNodeType.Element)
            {
                XmlReader_XmlNode node = (XmlReader_XmlNode)_xmlNodes.Peek();

                return(StringRefEquals(node.LocalName, localname) &&
                       StringRefEquals(node.NamespaceURI, ns));
            }

            return(false);
        }
コード例 #3
0
ファイル: XmlReader.cs プロジェクト: yisea123/NETMF-LPC
        /// <summary>
        /// Checks that the current content node is an element with the given LocalName and
        /// NamespaceURI and advances the reader to the next node.
        /// </summary>
        /// <param name="localname">The local name of the element.</param>
        /// <param name="ns">The namespace URI of the element.</param>
        public virtual void ReadStartElement(string localname, string ns)
        {
            if (MoveToContent() != XmlNodeType.Element)
            {
                throw new XmlException(XmlException.XmlExceptionErrorCode.InvalidNodeType);
            }

            XmlReader_XmlNode node = (XmlReader_XmlNode)_xmlNodes.Peek();

            if (StringRefEquals(node.LocalName, localname) &&
                StringRefEquals(node.NamespaceURI, ns))
            {
                Read();
            }
            else
            {
                throw new XmlException(XmlException.XmlExceptionErrorCode.ElementNotFound);
            }
        }