当前位置: 首页>>代码示例>>C#>>正文


C# XmlReader.MoveToNextAttribute方法代码示例

本文整理汇总了C#中System.IO.XmlReader.MoveToNextAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.MoveToNextAttribute方法的具体用法?C# XmlReader.MoveToNextAttribute怎么用?C# XmlReader.MoveToNextAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.XmlReader的用法示例。


在下文中一共展示了XmlReader.MoveToNextAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConsumeReader

        protected void ConsumeReader(XmlReader reader)
        {
            while (reader.Read())
            {
                string x = reader.Name + reader.NodeType + reader.Value;
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.HasAttributes)
                    {
                        reader.MoveToFirstAttribute();
                        int index = 0;
                        reader.MoveToAttribute(index);
                        index++;
                        while (reader.MoveToNextAttribute())
                        {
                            string name = reader.Name;
                            string value;

                            value = reader.GetAttribute(index);
                            value = reader.GetAttribute(name);
                            value = reader.GetAttribute(name, null);

                            reader.ReadAttributeValue();
                            reader.MoveToAttribute(index);
                            reader.MoveToAttribute(name, null);
                            index++;
                        }
                    }
                }
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    reader.Skip();
                }
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:35,代码来源:ReaderFactory.cs

示例2: LoadFromReader

        /// <summary>
        /// Create a writer that can be used to create nodes in this document.  The root node will be assigned "baseUri", and flags
        /// can be passed to indicate that names should be atomized by the builder and/or a fragment should be created.
        /// </summary>
        internal void LoadFromReader(XmlReader reader, XmlSpace space)
        {
            XPathDocumentBuilder builder;
            IXmlLineInfo lineInfo;
            string xmlnsUri;
            bool topLevelReader;
            int initialDepth;

            if (reader == null)
                throw new ArgumentNullException(nameof(reader));

            // Determine line number provider
            lineInfo = reader as IXmlLineInfo;
            if (lineInfo == null || !lineInfo.HasLineInfo())
                lineInfo = null;
            _hasLineInfo = (lineInfo != null);

            _nameTable = reader.NameTable;
            builder = new XPathDocumentBuilder(this, lineInfo, reader.BaseURI, LoadFlags.None);

            try
            {
                // Determine whether reader is in initial state
                topLevelReader = (reader.ReadState == ReadState.Initial);
                initialDepth = reader.Depth;

                // Get atomized xmlns uri
                Debug.Assert((object)_nameTable.Get(string.Empty) == (object)string.Empty, "NameTable must contain atomized string.Empty");
                xmlnsUri = _nameTable.Get(XmlReservedNs.NsXmlNs);

                // Read past Initial state; if there are no more events then load is complete
                if (topLevelReader && !reader.Read())
                    return;

                // Read all events
                do
                {
                    // If reader began in intermediate state, return when all siblings have been read
                    if (!topLevelReader && reader.Depth < initialDepth)
                        return;

                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            {
                                bool isEmptyElement = reader.IsEmptyElement;

                                builder.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.BaseURI);

                                // Add attribute and namespace nodes to element
                                while (reader.MoveToNextAttribute())
                                {
                                    string namespaceUri = reader.NamespaceURI;

                                    if ((object)namespaceUri == (object)xmlnsUri)
                                    {
                                        if (reader.Prefix.Length == 0)
                                        {
                                            // Default namespace declaration "xmlns"
                                            Debug.Assert(reader.LocalName == "xmlns");
                                            builder.WriteNamespaceDeclaration(string.Empty, reader.Value);
                                        }
                                        else
                                        {
                                            Debug.Assert(reader.Prefix == "xmlns");
                                            builder.WriteNamespaceDeclaration(reader.LocalName, reader.Value);
                                        }
                                    }
                                    else
                                    {
                                        builder.WriteStartAttribute(reader.Prefix, reader.LocalName, namespaceUri);
                                        builder.WriteString(reader.Value, TextBlockType.Text);
                                        builder.WriteEndAttribute();
                                    }
                                }

                                if (isEmptyElement)
                                    builder.WriteEndElement(true);
                                break;
                            }

                        case XmlNodeType.EndElement:
                            builder.WriteEndElement(false);
                            break;

                        case XmlNodeType.Text:
                        case XmlNodeType.CDATA:
                            builder.WriteString(reader.Value, TextBlockType.Text);
                            break;

                        case XmlNodeType.SignificantWhitespace:
                            if (reader.XmlSpace == XmlSpace.Preserve)
                                builder.WriteString(reader.Value, TextBlockType.SignificantWhitespace);
                            else
                                // Significant whitespace without xml:space="preserve" is not significant in XPath/XQuery data model
                                goto case XmlNodeType.Whitespace;
//.........这里部分代码省略.........
开发者ID:Corillian,项目名称:corefx,代码行数:101,代码来源:XPathDocument.cs

示例3: ReadElementFrom

 private void ReadElementFrom(XmlReader r, LoadOptions o)
 {
     if (r.ReadState != ReadState.Interactive) throw new InvalidOperationException(SR.InvalidOperation_ExpectedInteractive);
     name = XNamespace.Get(r.NamespaceURI).GetName(r.LocalName);
     if ((o & LoadOptions.SetBaseUri) != 0)
     {
         string baseUri = r.BaseURI;
         if (!string.IsNullOrEmpty(baseUri))
         {
             SetBaseUri(baseUri);
         }
     }
     IXmlLineInfo li = null;
     if ((o & LoadOptions.SetLineInfo) != 0)
     {
         li = r as IXmlLineInfo;
         if (li != null && li.HasLineInfo())
         {
             SetLineInfo(li.LineNumber, li.LinePosition);
         }
     }
     if (r.MoveToFirstAttribute())
     {
         do
         {
             XAttribute a = new XAttribute(XNamespace.Get(r.Prefix.Length == 0 ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value);
             if (li != null && li.HasLineInfo())
             {
                 a.SetLineInfo(li.LineNumber, li.LinePosition);
             }
             AppendAttributeSkipNotify(a);
         } while (r.MoveToNextAttribute());
         r.MoveToElement();
     }
     if (!r.IsEmptyElement)
     {
         r.Read();
         ReadContentFrom(r, o);
     }
     r.Read();
 }
开发者ID:gitter-badger,项目名称:corefx,代码行数:41,代码来源:XElement.cs

示例4: BuildSubtree

        internal static void BuildSubtree(XmlReader reader, XmlWriter writer)
        {
            // important (perf) string literal...
            string xmlnsUri = XmlConst.ReservedNsXmlNs; // http://www.w3.org/2000/xmlns/
            ReadState readState = reader.ReadState;

            if (readState != ReadState.Initial
                && readState != ReadState.Interactive)
            {
                throw new ArgumentException(SR.Xml_InvalidOperation, "reader");
            }
            int level = 0;
            if (readState == ReadState.Initial)
            {
                if (!reader.Read())
                    return;
                level++; // if start in initial, read everything (not just first)
            }
            do
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        bool isEmptyElement = reader.IsEmptyElement;

                        while (reader.MoveToNextAttribute())
                        {
                            if ((object)reader.NamespaceURI == (object)xmlnsUri)
                            {
                                if (reader.Prefix.Length == 0)
                                {
                                    // Default namespace declaration "xmlns"
                                    Debug.Assert(reader.LocalName == "xmlns");
                                    writer.WriteAttributeString("", "xmlns", xmlnsUri, reader.Value);
                                }
                                else
                                {
                                    Debug.Assert(reader.Prefix == "xmlns");
                                    writer.WriteAttributeString("xmlns", reader.LocalName, xmlnsUri, reader.Value);
                                }
                            }
                            else
                            {
                                writer.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                                writer.WriteString(reader.Value);
                                writer.WriteEndAttribute();
                            }
                        }

                        reader.MoveToElement();
                        if (isEmptyElement)
                        {
                            // there might still be a value, if there is a default value specified in the schema
                            writer.WriteEndElement();
                        }
                        else
                        {
                            level++;
                        }
                        break;
                    case XmlNodeType.EndElement:
                        writer.WriteFullEndElement();
                        //should not read beyond the level of the reader's original position.
                        level--;
                        break;
                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                        writer.WriteString(reader.Value);
                        break;
                    case XmlNodeType.SignificantWhitespace:
                    case XmlNodeType.Whitespace:
                        writer.WriteString(reader.Value);
                        break;
                    case XmlNodeType.Comment:
                        writer.WriteComment(reader.Value);
                        break;
                    case XmlNodeType.ProcessingInstruction:
                        writer.WriteProcessingInstruction(reader.LocalName, reader.Value);
                        break;
                    case XmlNodeType.EntityReference:
                        reader.ResolveEntity();
                        break;
                    case XmlNodeType.EndEntity:
                    case XmlNodeType.None:
                    case XmlNodeType.DocumentType:
                    case XmlNodeType.XmlDeclaration:
                        break;
                    case XmlNodeType.Attribute:
                        if ((object)reader.NamespaceURI == (object)xmlnsUri)
                        {
                            if (reader.Prefix.Length == 0)
                            {
                                // Default namespace declaration "xmlns"
                                Debug.Assert(reader.LocalName == "xmlns");
                                writer.WriteAttributeString("", "xmlns", xmlnsUri, reader.Value);
                            }
                            else
                            {
                                Debug.Assert(reader.Prefix == "xmlns");
//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:XPathNavigator.cs

示例5: ReadAttributes

	    private void ReadAttributes( XPathElement parent, XmlReader reader ) {
            XPathNamespace last = null;
		    while(reader.MoveToNextAttribute()) {
		        documentIndex++;
                if ((object)reader.NamespaceURI == (object)xmlnsUri) {
                    XPathNamespace tmp = new XPathNamespace(reader.Prefix == string.Empty ? string.Empty : reader.LocalName, reader.Value, documentIndex);
                    tmp.next = last;
                    last = tmp;
                }
                else {
			        parent.AppendAttribute(new XPathAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.Value, documentIndex));
			        if (htElementIdMap != null) {
    			        Object attrname = htElementIdMap[new XmlQualifiedName(parent.Name, parent.Prefix)] ;
                        if (attrname != null && new XmlQualifiedName(reader.Name, reader.Prefix).Equals(attrname)) {
                            if (htElementIDAttrDecl[reader.Value] == null) {
                                htElementIDAttrDecl.Add(reader.Value, parent);
                            }
                        }
                    }
                }
		    }
            if (last != null) {
                parent.AppendNamespaces(last);
            }
	    }
开发者ID:ArildF,项目名称:masters,代码行数:25,代码来源:xpathdocument.cs


注:本文中的System.IO.XmlReader.MoveToNextAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。