通过


XmlValidatingReader.GetAttribute 方法

定义

获取特性的值。

重载

名称 说明
GetAttribute(Int32)

获取具有指定索引的属性的值。

GetAttribute(String)

获取具有指定名称的属性的值。

GetAttribute(String, String)

获取具有指定本地名称和命名空间统一资源标识符(URI)的属性的值。

GetAttribute(Int32)

Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs

获取具有指定索引的属性的值。

public:
 override System::String ^ GetAttribute(int i);
public override string GetAttribute(int i);
override this.GetAttribute : int -> string
Public Overrides Function GetAttribute (i As Integer) As String

参数

i
Int32

属性的索引。 索引从零开始。 (第一个属性具有索引 0。)

返回

指定属性的值。

例外

参数 i 小于 0 或大于或等于 AttributeCount

注解

此方法不会移动读取器。

注释

XmlValidatingReader 类在 .NET Framework 2.0 中已过时。 可以使用类和Create方法创建验证XmlReader实例XmlReaderSettings。 有关详细信息,请参阅 XmlReader 引用页的“备注”部分。

另请参阅

适用于

GetAttribute(String)

Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs

获取具有指定名称的属性的值。

public:
 override System::String ^ GetAttribute(System::String ^ name);
public override string? GetAttribute(string name);
public override string GetAttribute(string name);
override this.GetAttribute : string -> string
Public Overrides Function GetAttribute (name As String) As String

参数

name
String

特性的限定名称。

返回

指定属性的值。 如果未找到该属性, null 则返回。

注解

注释

XmlValidatingReader 类在 .NET Framework 2.0 中已过时。 可以使用类和Create方法创建验证XmlReader实例XmlReaderSettings。 有关详细信息,请参阅 XmlReader 引用页的“备注”部分。

此方法不会移动读取器。

如果读取器定位在节点上 DocumentType ,则此方法可用于获取 PUBLIC 和 SYSTEM 文本,例如 reader.GetAttribute("PUBLIC")

另请参阅

适用于

GetAttribute(String, String)

Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs
Source:
XmlValidatingReader.cs

获取具有指定本地名称和命名空间统一资源标识符(URI)的属性的值。

public:
 override System::String ^ GetAttribute(System::String ^ localName, System::String ^ namespaceURI);
public override string? GetAttribute(string localName, string? namespaceURI);
public override string GetAttribute(string localName, string namespaceURI);
override this.GetAttribute : string * string -> string
Public Overrides Function GetAttribute (localName As String, namespaceURI As String) As String

参数

localName
String

特性的本地名称。

namespaceURI
String

属性的命名空间 URI。

返回

指定属性的值。 如果未找到该属性, null 则返回。 此方法不会移动读取器。

注解

注释

XmlValidatingReader 类在 .NET Framework 2.0 中已过时。 可以使用类和Create方法创建验证XmlReader实例XmlReaderSettings。 有关详细信息,请参阅 XmlReader 引用页的“备注”部分。

以下 XML 包含特定命名空间中的属性:

<test xmlns:dt="urn:datatypes" dt:type="int"/>

可以使用一个参数(前缀和本地名称)或两个参数(本地名称和命名空间 URI)查找 dt:type 属性:

String dt = reader.GetAttribute("dt:type");
String dt2 = reader.GetAttribute("type","urn:datatypes");

若要查找 xmlns:dt 属性,请使用下列参数之一:

String dt3 = reader.GetAttribute("xmlns:dt");
String dt4 = reader.GetAttribute("dt",http://www.w3.org/2000/xmlns/);

还可以使用 Prefix 属性获取此信息。

另请参阅

适用于