XmlElement.GetAttributeNode Metod

Definition

Returnera den angivna XmlAttribute.

Överlagringar

Name Description
GetAttributeNode(String)

XmlAttribute Returnerar med det angivna namnet.

GetAttributeNode(String, String)

XmlAttribute Returnerar med det angivna lokala namnet och namnområdes-URI:n.

GetAttributeNode(String)

Källa:
XmlElement.cs
Källa:
XmlElement.cs
Källa:
XmlElement.cs
Källa:
XmlElement.cs
Källa:
XmlElement.cs

XmlAttribute Returnerar med det angivna namnet.

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

Parametrar

name
String

Namnet på attributet som ska hämtas. Det här är ett kvalificerat namn. Den matchas mot egenskapen för Name den matchande noden.

Returer

Angivet XmlAttribute eller null om ett matchande attribut inte hittades.

Exempel

I följande exempel kontrolleras om elementet har det angivna attributet.

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

Gäller för

GetAttributeNode(String, String)

Källa:
XmlElement.cs
Källa:
XmlElement.cs
Källa:
XmlElement.cs
Källa:
XmlElement.cs
Källa:
XmlElement.cs

XmlAttribute Returnerar med det angivna lokala namnet och namnområdes-URI:n.

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

Parametrar

localName
String

Attributets lokala namn.

namespaceURI
String

Attributets namnområdes-URI.

Returer

Angivet XmlAttribute eller null om ett matchande attribut inte hittades.

Gäller för