XmlElement.GetAttributeNode XmlElement.GetAttributeNode XmlElement.GetAttributeNode XmlElement.GetAttributeNode Method

定義

傳回指定的 XmlAttributeReturn the specified XmlAttribute.

多載

GetAttributeNode(String) GetAttributeNode(String) GetAttributeNode(String) GetAttributeNode(String)

傳回具有指定名稱的 XmlAttributeReturns the XmlAttribute with the specified name.

GetAttributeNode(String, String) GetAttributeNode(String, String) GetAttributeNode(String, String) GetAttributeNode(String, String)

傳回具有指定區域名稱和命名空間 URI 的 XmlAttributeReturns the XmlAttribute with the specified local name and namespace URI.

GetAttributeNode(String) GetAttributeNode(String) GetAttributeNode(String) GetAttributeNode(String)

傳回具有指定名稱的 XmlAttributeReturns the XmlAttribute with the specified name.

public:
 virtual System::Xml::XmlAttribute ^ GetAttributeNode(System::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 String String String

要擷取之屬性的名稱。The name of the attribute to retrieve. 這是限定名稱。This is a qualified name. 它會與符合節點的 Name 屬性比對。It is matched against the Name property of the matching node.

傳回

指定的 XmlAttribute;如果找不到相符的屬性,則為 nullThe specified XmlAttribute or null if a matching attribute was not found.

範例

下列範例會檢查項目是否具有指定的屬性。The following example checks to see if the element has the specified attribute.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew 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 );
   }
}

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) GetAttributeNode(String, String) GetAttributeNode(String, String) GetAttributeNode(String, String)

傳回具有指定區域名稱和命名空間 URI 的 XmlAttributeReturns the XmlAttribute with the specified local name and namespace URI.

public:
 virtual System::Xml::XmlAttribute ^ GetAttributeNode(System::String ^ localName, System::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 String String String

屬性的本機名稱。The local name of the attribute.

namespaceURI
String String String String

屬性的命名空間 URI。The namespace URI of the attribute.

傳回

指定的 XmlAttribute;如果找不到相符的屬性,則為 nullThe specified XmlAttribute or null if a matching attribute was not found.

適用於