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


C# XmlReader.Read方法代码示例

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


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

示例1: StartParsing

        public void StartParsing(XmlReader reader, string targetNamespace) {
            this.reader = reader;
            positionInfo = PositionInfo.GetPositionInfo(reader);
            namespaceManager = reader.NamespaceManager;
            if (namespaceManager == null) {
                namespaceManager = new XmlNamespaceManager(nameTable);
                isProcessNamespaces = true;
            } 
            else {
                isProcessNamespaces = false;
            }
            while (reader.NodeType != XmlNodeType.Element && reader.Read()) {}

            markupDepth = int.MaxValue;
            schemaXmlDepth = reader.Depth;
            SchemaType rootType = schemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
            
            string code;
            if (!CheckSchemaRoot(rootType, out code)) {
                throw new XmlSchemaException(code, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition);
            }
            
            if (schemaType == SchemaType.XSD) {
                schema = new XmlSchema();
                schema.BaseUri = new Uri(reader.BaseURI, UriKind.RelativeOrAbsolute);
                builder = new XsdBuilder(reader, namespaceManager, schema, nameTable, schemaNames, eventHandler);
            }
            else {  
                Debug.Assert(schemaType == SchemaType.XDR);
                xdrSchema = new SchemaInfo();
                xdrSchema.SchemaType = SchemaType.XDR;
                builder = new XdrBuilder(reader, namespaceManager, xdrSchema, targetNamespace, nameTable, schemaNames, eventHandler);
                ((XdrBuilder)builder).XmlResolver = xmlResolver;
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:35,代码来源:Parser.cs

示例2: XDeclaration

 internal XDeclaration(XmlReader r)
 {
     _version = r.GetAttribute("version");
     _encoding = r.GetAttribute("encoding");
     _standalone = r.GetAttribute("standalone");
     r.Read();
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:XDeclaration.cs

示例3: CheckIgnores

        public bool CheckIgnores(XmlReader reader, bool pi, bool comm, bool ws)
        {
            if (reader == null)
                return false;

            _commentCount = 0;
            _piCount = 0;
            _wsCount = 0;

            while (reader.Read())
            {
                if (XmlNodeType.ProcessingInstruction == reader.NodeType)
                {
                    ++_piCount;
                }
                if (XmlNodeType.SignificantWhitespace == reader.NodeType)
                {
                    ++_wsCount;
                }
                if (XmlNodeType.Comment == reader.NodeType)
                {
                    ++_commentCount;
                }
            }

            if (pi && _piCount > 0)
            {
                CError.WriteLineIgnore("ProcessingInstruction Found");
                CError.WriteLineIgnore(reader.Name);
                CError.WriteLineIgnore(">" + reader.Value + "<");
                return false;
            }
            if (comm && _commentCount > 0)
            {
                CError.WriteLineIgnore("Comment Found");
                CError.WriteLineIgnore(reader.Name);
                CError.WriteLineIgnore(">" + reader.Value + "<");
                return false;
            }
            if (ws && _wsCount > 0)
            {
                CError.WriteLineIgnore("Significant Whitespace Found");
                CError.WriteLineIgnore(reader.Name);
                CError.WriteLineIgnore(">" + reader.Value + "<");
                return false;
            }
            return true;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:48,代码来源:FilterSettings.cs

示例4: 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

示例5: Parse

 public SchemaType Parse(XmlReader reader, string targetNamespace)
 {
     StartParsing(reader, targetNamespace);
     while (ParseReaderNode() && reader.Read()) { }
     return FinishParsing();
 }
开发者ID:dotnet,项目名称:corefx,代码行数:6,代码来源:Parser.cs

示例6: NestRead

 private XmlReader NestRead(XmlReader r)
 {
     r.Read();
     r.Read();
     if (!(r.Name == "elem0" && r.NodeType == XmlNodeType.Element))
     {
         CError.WriteLine(r.Name);
         NestRead(r.ReadSubtree());
     }
     r.Dispose();
     return r;
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:ReadSubTree.cs

示例7: 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

示例8: 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

示例9: 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

示例10: ReadChildNodes

	    private void ReadChildNodes( XPathContainer parent, string parentBaseUri, XmlReader reader, PositionInfo positionInfo ) {
		    do {
		        documentIndex++;
			    switch( reader.NodeType ) {
				case XmlNodeType.Element: {
                    string baseUri = reader.BaseURI;
                    XPathElement e = null;
                    if( reader.IsEmptyElement ) {
                        e = new XPathEmptyElement( reader.Prefix, reader.LocalName, reader.NamespaceURI, positionInfo.LineNumber, positionInfo.LinePosition, parent.topNamespace, documentIndex );
    					ReadAttributes( e, reader );
                    }
                    else {
                        e = new XPathElement( reader.Prefix, reader.LocalName, reader.NamespaceURI, positionInfo.LineNumber, positionInfo.LinePosition, parent.topNamespace, documentIndex );
    					ReadAttributes( e, reader );
    					reader.Read();
	    				ReadChildNodes( e, baseUri, reader, positionInfo );
                    }
                    if (parentBaseUri != baseUri) {
                        // We can't user Ref.Equial Because Reader fails to fully atomize base Uri.
                        if (elementBaseUriMap == null) {
                            elementBaseUriMap = new Hashtable();
                        }
                        elementBaseUriMap[e] = baseUri;
                    }
                    parent.AppendChild( e );
                    break;
				}	

				case XmlNodeType.Comment:
                    parent.AppendChild( new XPathComment( reader.Value, documentIndex ) );
                    break;

				case XmlNodeType.ProcessingInstruction:
                    parent.AppendChild( new XPathProcessingInstruction( reader.LocalName, reader.Value, documentIndex ) );
                    break;

				case XmlNodeType.SignificantWhitespace:
                    if( reader.XmlSpace == XmlSpace.Preserve ) {
                        parent.AppendSignificantWhitespace( reader.Value, positionInfo.LineNumber, positionInfo.LinePosition, documentIndex );
                    }
                    else {
                        // SWS without xml:space='preserve' is not really significant for XPath.
                        // so we treat it as just WS
                        goto case XmlNodeType.Whitespace;
                    }
                    break;

				case XmlNodeType.Whitespace:
                    if( space == XmlSpace.Preserve ) {
                        parent.AppendWhitespace( reader.Value, positionInfo.LineNumber, positionInfo.LinePosition, documentIndex );
                    }
                    break;

				case XmlNodeType.CDATA:
				case XmlNodeType.Text:
                    parent.AppendText( reader.Value, positionInfo.LineNumber, positionInfo.LinePosition, documentIndex );
                    break;

                case XmlNodeType.EntityReference:
                    reader.ResolveEntity();
                    reader.Read();
                    ReadChildNodes( parent, parentBaseUri, reader, positionInfo);
                    break;

                case XmlNodeType.EndEntity:
				case XmlNodeType.EndElement:
                case XmlNodeType.None:
					return;

                case XmlNodeType.DocumentType:
                    XmlValidatingReader vr = reader as XmlValidatingReader;
                    if ( vr != null ) {
                        SchemaInfo info = vr.GetSchemaInfo();
                        if ( info != null ) {
                            GetIDInfo( info);
                        }
                    }
                    break;
                case XmlNodeType.XmlDeclaration:
                default:
                    break;
			    }
		    }while( reader.Read() );
	    }
开发者ID:ArildF,项目名称:masters,代码行数:84,代码来源:xpathdocument.cs

示例11: Load

	    private void Load( XmlReader reader ) {
            nt = reader.NameTable;
            baseURI = reader.BaseURI;
            Debug.Assert(baseURI != null, "uri can't be null, isn't it?");
            xmlnsUri = (nt != null ? nt.Add(XmlReservedNs.NsXmlNs) : XmlReservedNs.NsXmlNs);
	        PositionInfo positionInfo = PositionInfo.GetPositionInfo(reader);
            if ( reader.ReadState == ReadState.Initial ) {
                if ( !reader.Read() )
                    return;
            }
		    ReadChildNodes( root, baseURI, reader, positionInfo );
	    }
开发者ID:ArildF,项目名称:masters,代码行数:12,代码来源:xpathdocument.cs

示例12: DeserializeArray

        private static object DeserializeArray(XmlReader xmlReader)
        {
            string startingElementName = xmlReader.Name;
            xmlReader.Read();
            string arrayType = xmlReader.Name;

            ArrayList array = new ArrayList();
            Type returnType = null;

            while (xmlReader.Name != startingElementName)
            {
                string tempValue = xmlReader.ReadElementString();

                switch (arrayType)
                {
                    case "boolean":
                        returnType = returnType ?? typeof(bool);
                        array.Add(tempValue == "true");
                        break;

                    // TODO: this is not an array but a base64 encoded string
                    //case "byte":
                    //    //returnType = returnType ?? typeof(bool);
                    //    //return Convert.FromBase64String(tempValue);
                    //    //throw new Exception("Should never reach this");
                    //    break;

                    case "byte":
                        returnType = returnType ?? typeof(sbyte);
                        array.Add(Convert.ToSByte(tempValue));
                        break;

                    case "char":
                        returnType = returnType ?? typeof(char);
                        array.Add(Convert.ToChar(Convert.ToByte(tempValue)));
                        break;

                    case "dateTime":
                        returnType = returnType ?? typeof(DateTime);
                        array.Add(GetDateTimeFromString(tempValue));
                        break;

                    case "double":
                        returnType = returnType ?? typeof(double);
                        array.Add(Convert.ToDouble(tempValue));
                        break;

                    case "guid":
                        returnType = returnType ?? typeof(Guid);
                        array.Add(GetGuidFromString(tempValue));
                        break;

                    case "short":
                        returnType = returnType ?? typeof(short);
                        array.Add(Convert.ToInt16(tempValue));
                        break;
                    case "unsignedShort":
                        returnType = returnType ?? typeof(ushort);
                        array.Add(Convert.ToUInt16(tempValue));
                        break;

                    case "int":
                        returnType = returnType ?? typeof(int);
                        array.Add(Convert.ToInt32(tempValue));
                        break;
                    case "unsignedInt":
                        returnType = returnType ?? typeof(uint);
                        array.Add(Convert.ToUInt32(tempValue));
                        break;

                    case "long":
                        returnType = returnType ?? typeof(long);
                        array.Add(Convert.ToInt64(tempValue));
                        break;
                    case "unsignedLong":
                        returnType = returnType ?? typeof(ulong);
                        array.Add(Convert.ToUInt64(tempValue));
                        break;

                    case "float":
                        returnType = returnType ?? typeof(float);
                        array.Add((Single)Convert.ToDouble(tempValue));
                        break;

                    case "string":
                        returnType = returnType ?? typeof(string);
                        array.Add(tempValue);
                        break;

                    default:
                        returnType = returnType ?? typeof(object);
                        break;
                }
            }

            return array.ToArray(returnType);
        }
开发者ID:Rhesos,项目名称:SDKGadgeteer,代码行数:97,代码来源:XmlSerializer.cs


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