XmlElement.GetAttributeNode 方法

定义

返回指定的 XmlAttribute

重载

名称 说明
GetAttributeNode(String)

返回 XmlAttribute 具有指定名称的函数。

GetAttributeNode(String, String)

返回 XmlAttribute 具有指定的本地名称和命名空间 URI。

GetAttributeNode(String)

Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs

返回 XmlAttribute 具有指定名称的函数。

public:
 virtual System::Xml::XmlAttribute ^ GetAttributeNode(System::String ^ name);
public virtual System.Xml.XmlAttribute GetAttributeNode(string name);
public virtual System.Xml.XmlAttribute? GetAttributeNode(string name);
abstract member GetAttributeNode : string -> System.Xml.XmlAttribute
override this.GetAttributeNode : string -> System.Xml.XmlAttribute
Public Overridable Function GetAttributeNode (name As String) As XmlAttribute

参数

name
String

要检索的属性的名称。 这是限定的名称。 它与 Name 匹配节点的属性匹配。

返回

指定的 XmlAttributenull 找不到匹配的属性。

示例

以下示例检查该元素是否具有指定的属性。

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    XmlElement root = doc.DocumentElement;

    // Check to see if the element has a genre attribute.
    if (root.HasAttribute("genre")){
      XmlAttribute attr = root.GetAttributeNode("genre");
      Console.WriteLine(attr.Value);
   }
  }
}
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
                "<title>Pride And Prejudice</title>" & _
                "</book>")      

    Dim root as XmlElement = doc.DocumentElement

    ' Check to see if the element has a genre attribute.
    if (root.HasAttribute("genre"))
     Dim attr as XmlAttribute = root.GetAttributeNode("genre")
     Console.WriteLine(attr.Value)
    end if
       
    Console.WriteLine("Display the modified XML...")
    Console.WriteLine(doc.InnerXml)

  end sub
end class

适用于

GetAttributeNode(String, String)

Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs

返回 XmlAttribute 具有指定的本地名称和命名空间 URI。

public:
 virtual System::Xml::XmlAttribute ^ GetAttributeNode(System::String ^ localName, System::String ^ namespaceURI);
public virtual System.Xml.XmlAttribute GetAttributeNode(string localName, string namespaceURI);
public virtual System.Xml.XmlAttribute? GetAttributeNode(string localName, string? namespaceURI);
abstract member GetAttributeNode : string * string -> System.Xml.XmlAttribute
override this.GetAttributeNode : string * string -> System.Xml.XmlAttribute
Public Overridable Function GetAttributeNode (localName As String, namespaceURI As String) As XmlAttribute

参数

localName
String

特性的本地名称。

namespaceURI
String

特性的命名空间 URI。

返回

指定的 XmlAttributenull 找不到匹配的属性。

适用于