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


C# XmlReader.ReadAttributeValue方法代码示例

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


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

示例1: CheckPerspexRoot

        public static bool CheckPerspexRoot(XmlReader reader)
        {
            try
            {
                while (!reader.IsStartElement())
                {
                    reader.Read();
                }
                if (!reader.MoveToFirstAttribute())
                    return false;
                do
                {
                    if (reader.Name == "xmlns")
                    {
                        reader.ReadAttributeValue();
                        return reader.Value.ToLower() == PerspexNamespace;
                    }

                } while (reader.MoveToNextAttribute());
                return false;
            }
            catch
            {
                return false;
            }
        }
开发者ID:rdterner,项目名称:PerspexVS,代码行数:26,代码来源:Utils.cs

示例2: while

        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            reader.ReadStartElement();

            while (reader.GetAttribute("key") != null)
            {
                reader.ReadAttributeValue();
                this.Add(reader.GetAttribute("key"), reader.GetAttribute("value"));

                reader.ReadStartElement("property");
            }
            reader.ReadEndElement();
        }
开发者ID:matsuko,项目名称:Msticky,代码行数:13,代码来源:XmlSerializableNameValueCollection.cs

示例3: Run

		public static void Run(XmlReader reader, bool includeAttributes, bool includeAttributeValues = true)
		{
			using (StreamWriter output = File.CreateText(Path.Combine(Program.TempPath, reader.GetType().Name + "-output.csv"))) {
				var properties = typeof(XmlReader).GetProperties(BindingFlags.Public | BindingFlags.Instance)
					.Where(p => p.GetIndexParameters().Length == 0 && !ignoredProperties.Contains(p.Name))
					.ToArray();
				output.WriteLine(CSV(properties.Select(p => p.Name)));
				do {
					output.WriteLine(CSV(properties.Select(p => ToString(p.GetValue(reader, null)))));
					if (includeAttributes && reader.HasAttributes) {
						for (int i = 0; i < reader.AttributeCount; i++) {
							reader.MoveToAttribute(i);
							output.WriteLine(CSV(properties.Select(p => ToString(p.GetValue(reader, null)))));
							if (includeAttributeValues) {
								reader.ReadAttributeValue();
								output.WriteLine(CSV(properties.Select(p => ToString(p.GetValue(reader, null)))));
							}
						}
					}
				} while (reader.Read());
				output.WriteLine(CSV(properties.Select(p => ToString(p.GetValue(reader, null)))));
			}
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:23,代码来源:XmlReaderTest.cs

示例4: VerifyAttributeValue

        private void VerifyAttributeValue(XmlReader expectedReader, XmlReader actualReader, bool useReadAttributeValue)
        {
            this.VerifyReaderNodesAreEqual(expectedReader, actualReader);
            if (expectedReader.NodeType != XmlNodeType.Attribute || !useReadAttributeValue)
            {
                return;
            }

            while (expectedReader.ReadAttributeValue())
            {
                this.Assert.AreEqual(true, actualReader.ReadAttributeValue(), "ReadAttributeValue differs.");
                this.VerifyReaderNodesAreEqual(expectedReader, actualReader);
            }

            this.Assert.AreEqual(false, actualReader.ReadAttributeValue(), "ReadAttributeValue differs.");
            this.VerifyReaderNodesAreEqual(expectedReader, actualReader);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:17,代码来源:BufferingXmlReaderTests.cs

示例5: WriteAttributes

        /// <summary>
        /// This method is overriden to filter out attributes which are not allowed
        /// </summary>
        public override void WriteAttributes(XmlReader reader, bool defattr)
        {
            if( this.FilterOutput )
            {
                // The following code is copied from implementation of XmlWriter's
                // WriteAttributes method.
                if (reader == null)
                {
                    throw new ArgumentNullException("reader");
                }
                if ((reader.NodeType == XmlNodeType.Element) || (reader.NodeType == XmlNodeType.XmlDeclaration))
                {
                    if (reader.MoveToFirstAttribute())
                    {
                        this.WriteAttributes(reader, defattr);
                        reader.MoveToElement();
                    }
                }
                else
                {
                    if (reader.NodeType != XmlNodeType.Attribute)
                    {
                        throw new XmlException("Xml_InvalidPosition");
                    }
                    do
                    {
                        if (defattr || !reader.IsDefault)
                        {
                            // Check if the attribute is allowed
                            bool canWrite = false;
                            string attributeLocalName = reader.LocalName.ToLower();
                            foreach( string name in this.AllowedAttributes )
                            {
                                if( name == attributeLocalName )
                                {
                                    canWrite = true;
                                    break;
                                }
                            }

                            // If allowed, write the attribute
                            if( canWrite )
                                this.WriteStartAttribute(reader.Prefix, attributeLocalName,
                                    reader.NamespaceURI);

                            while (reader.ReadAttributeValue())
                            {
                                if (reader.NodeType == XmlNodeType.EntityReference)
                                {
                                    if( canWrite ) this.WriteEntityRef(reader.Name);
                                    continue;
                                }
                                if( canWrite )this.WriteString(reader.Value);
                            }
                            if( canWrite ) this.WriteEndAttribute();
                        }
                    } while (reader.MoveToNextAttribute());
                }
            }
            else
            {
                base.WriteAttributes( reader, defattr );
            }
        }
开发者ID:cmcginn,项目名称:Marketing,代码行数:67,代码来源:HtmlReaderWriter.cs

示例6: WriteAttributes

        public override void WriteAttributes(XmlReader reader, bool defattr)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if ((reader.NodeType == XmlNodeType.Element) || (reader.NodeType == XmlNodeType.XmlDeclaration))
            {
                if (reader.MoveToFirstAttribute())
                {
                    this.WriteAttributes(reader, defattr);
                    reader.MoveToElement();
                }
            }
            else
            {
                if (reader.NodeType != XmlNodeType.Attribute)
                {
                    throw new XmlException("Xml_InvalidPosition");
                }
                do
                {
                    if (defattr || !reader.IsDefault)
                    {
                        string attributename = reader.LocalName.ToLower();

                        this.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);

                        while (reader.ReadAttributeValue())
                        {
                            if (reader.NodeType == XmlNodeType.EntityReference)
                            {
                                this.WriteEntityRef(reader.Name);
                                continue;
                            }

                            string value = reader.Value;

                            if (BaseHref != null
                                && LastStartElement == "a"
                                && attributename == "href")
                            {
                                value = HtmlUriExtractor.TryCreate(
                                    BaseHref, reader.Value, value);
                            }

                            if (BaseHref != null
                                && (LastStartElement == "img" || LastStartElement == "embed")
                                && attributename == "src")
                            {
                                value = HtmlUriExtractor.TryCreate(
                                    BaseHref, reader.Value, value);
                            }

                            this.WriteString(value);
                        }

                        this.WriteEndAttribute();
                    }
                } while (reader.MoveToNextAttribute());
            }
        }
开发者ID:dblock,项目名称:dblog,代码行数:63,代码来源:Web.Html.HtmlAbsoluteLinksWriter.cs

示例7: ReadEndpointCheck

 static void ReadEndpointCheck(XmlReader reader)
 {
     reader.MoveToAttribute ("name");
     if (!reader.ReadAttributeValue ())
         throw new ArgumentException ("Cannot read endpoint");
 }
开发者ID:miniBill,项目名称:DiagramDrawer,代码行数:6,代码来源:Line.cs

示例8: AppendAttributeValue

        internal int AppendAttributeValue(XmlReader reader)
        {
            int charactersWritten = 0;
            char quote = '"';//reader.QuoteChar;

            //
            // In !DOCTYPE, quote is '\0' for second public attribute.
            // Protect ourselves from writing invalid XML by always
            // supplying a valid quote char.
            //
            if (quote != '"' && quote != '\'') {
                quote = '"';
            }

            charactersWritten += Write(quote);
            while (reader.ReadAttributeValue()) {
                if (reader.NodeType == XmlNodeType.Text) {
                    charactersWritten += AppendEscapeXmlString(reader.Value, true, quote);
                }
                else {
                    charactersWritten += AppendEntityRef(reader.Name);
                }
            }

            charactersWritten += Write(quote);
            return charactersWritten;
        }
开发者ID:kichalla,项目名称:systemconfigurationport,代码行数:27,代码来源:XmlUtilWriter.cs

示例9: 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:johnhhm,项目名称:corefx,代码行数:35,代码来源:ReaderFactory.cs

示例10: WriteAttribute

		private void WriteAttribute (XmlReader reader, bool defattr)
		{
			if (!defattr && reader.IsDefault)
				return;

			WriteStartAttribute (reader.Prefix, reader.LocalName, reader.NamespaceURI);
#if MOONLIGHT
			// no ReadAttributeValue() in 2.1 profile.
			WriteString (reader.Value);
#else
			while (reader.ReadAttributeValue ()) {
				switch (reader.NodeType) {
				case XmlNodeType.Text:
					WriteString (reader.Value);
					break;
				case XmlNodeType.EntityReference:
					WriteEntityRef (reader.Name);
					break;
				}
			}
#endif
			WriteEndAttribute ();
		}
开发者ID:afaerber,项目名称:mono,代码行数:23,代码来源:XmlWriter.cs

示例11: WriteAttributes

        // XmlReader Helper Methods

        // Writes out all the attributes found at the current position in the specified XmlReader.
        public virtual void WriteAttributes(XmlReader reader, bool defattr)
        {
            if (null == reader)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.XmlDeclaration)
            {
                if (reader.MoveToFirstAttribute())
                {
                    WriteAttributes(reader, defattr);
                    reader.MoveToElement();
                }
            }
            else if (reader.NodeType != XmlNodeType.Attribute)
            {
                throw new XmlException(SR.Xml_InvalidPosition, string.Empty);
            }
            else
            {
                do
                {
                    // we need to check both XmlReader.IsDefault and XmlReader.SchemaInfo.IsDefault. 
                    // If either of these is true and defattr=false, we should not write the attribute out
                    if (defattr || !reader.IsDefaultInternal)
                    {
                        WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        while (reader.ReadAttributeValue())
                        {
                            if (reader.NodeType == XmlNodeType.EntityReference)
                            {
                                WriteEntityRef(reader.Name);
                            }
                            else
                            {
                                WriteString(reader.Value);
                            }
                        }
                        WriteEndAttribute();
                    }
                }
                while (reader.MoveToNextAttribute());
            }
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:48,代码来源:XmlWriter.cs

示例12: ReadAttributeNodeValue

		// Reads attribute from XmlReader and then creates attribute value children. XmlAttribute also uses this.
		internal void ReadAttributeNodeValue (XmlReader reader, XmlAttribute attribute)
		{
			while (reader.ReadAttributeValue ()) {
				if (reader.NodeType == XmlNodeType.EntityReference)
					attribute.AppendChild (CreateEntityReference (reader.Name), false); // omit node type check
				else
					// Children of Attribute is restricted to CharacterData and EntityReference (Comment is not allowed).
					attribute.AppendChild (CreateTextNode (reader.Value), false); // omit node type check
			}
		}
开发者ID:nzaugg,项目名称:mono,代码行数:11,代码来源:XmlDocument.cs

示例13: WriteAttributes

		/// <summary>
		/// This method is overriden to filter out attributes which are not allowed
		/// </summary>
		public override void WriteAttributes(XmlReader reader, bool defattr)
		{
			// The following code is copied from implementation of XmlWriter's
			// WriteAttributes method. 
			if (reader == null)
			{
				throw new ArgumentNullException("reader");
			}
			if ((reader.NodeType == XmlNodeType.Element) || (reader.NodeType == XmlNodeType.XmlDeclaration))
			{
				if (reader.MoveToFirstAttribute())
				{
					try
					{
						this.WriteAttributes(reader, defattr);
					}
					catch { }

					reader.MoveToElement();
				}
			}
			else
			{
				if (reader.NodeType != XmlNodeType.Attribute)
				{
					throw new XmlException("Xml_InvalidPosition");
				}
				do
				{
					try
					{
						if (defattr || !reader.IsDefault)
						{
							// Check if the attribute is allowed 
							string attributeLocalName = reader.LocalName.ToLower();
							AttributeTypes type = GetAttributeType(attributeLocalName);

							if (!type.Equals(AttributeTypes.Remove))
							{
								//parse the attribute
								string attribteValue = "";
								while (reader.ReadAttributeValue())
								{
									if (reader.NodeType.Equals(XmlNodeType.Text))
										attribteValue += reader.Value;
								}
								string parsedAttribteValue = ParseAttribute(attribteValue, type);

								//write the 
								if (parsedAttribteValue.Length > 0)
								{
									this.WriteStartAttribute(attributeLocalName);
									this.WriteRaw(parsedAttribteValue);
									//this.WriteString(parsedAttribteValue);
									this.WriteEndAttribute();
								}

							}
						}
					}
					catch { }
				}
				while (reader.MoveToNextAttribute());
			}
		}
开发者ID:davelondon,项目名称:dontstayin,代码行数:68,代码来源:HtmlCleaner.cs

示例14: MoveToXmlDeclAttributes

		public void MoveToXmlDeclAttributes (XmlReader xmlReader)
		{
			xmlReader.Read ();
			this.AssertNodeValues ("#1", xmlReader, 
				XmlNodeType.XmlDeclaration,
				0,
				false,
				"xml",
				String.Empty,
				"xml",
				String.Empty,
				"version=\"1.0\" standalone=\"yes\"",
				2);
			Assert.IsTrue (xmlReader.MoveToFirstAttribute (), "MoveToFirstAttribute");
			this.AssertNodeValues ("#2", xmlReader, 
				XmlNodeType.Attribute,
				0, // FIXME: might be 1
				false,
				"version",
				String.Empty,
				"version",
				String.Empty,
				"1.0",
				2);
			xmlReader.ReadAttributeValue ();
			this.AssertNodeValues ("#3", xmlReader, 
				XmlNodeType.Text,
				1, // FIXME might be 2
				false,
				String.Empty,
				null, // FIXME: should be String.Empty,
				String.Empty,
				null, // FIXME: should be String.Empty,
				"1.0",
				2);
			xmlReader.MoveToNextAttribute ();
			this.AssertNodeValues ("#4", xmlReader, 
				XmlNodeType.Attribute,
				0, // FIXME: might be 1
				false,
				"standalone",
				String.Empty,
				"standalone",
				String.Empty,
				"yes",
				2);
			xmlReader.ReadAttributeValue ();
			this.AssertNodeValues ("#5", xmlReader, 
				XmlNodeType.Text,
				1, // FIXME: might be 2
				false,
				String.Empty,
				null, // FIXME: should be String.Empty,
				String.Empty,
				null, // FIXME: should be String.Empty,
				"yes",
				2);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:58,代码来源:XmlReaderCommonTests.cs

示例15: WriteAttributes

 public virtual void WriteAttributes(XmlReader reader, bool defattr)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if ((reader.NodeType == XmlNodeType.Element) || (reader.NodeType == XmlNodeType.XmlDeclaration))
     {
         if (reader.MoveToFirstAttribute())
         {
             this.WriteAttributes(reader, defattr);
             reader.MoveToElement();
         }
     }
     else
     {
         if (reader.NodeType != XmlNodeType.Attribute)
         {
             throw new XmlException("Xml_InvalidPosition", string.Empty);
         }
         do
         {
             if (defattr || !reader.IsDefaultInternal)
             {
                 this.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                 while (reader.ReadAttributeValue())
                 {
                     if (reader.NodeType == XmlNodeType.EntityReference)
                     {
                         this.WriteEntityRef(reader.Name);
                     }
                     else
                     {
                         this.WriteString(reader.Value);
                     }
                 }
                 this.WriteEndAttribute();
             }
         }
         while (reader.MoveToNextAttribute());
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:42,代码来源:XmlWriter.cs


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