XmlElement.GetAttributeNode 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳指定的 XmlAttribute。
多載
| 名稱 | Description |
|---|---|
| GetAttributeNode(String) |
回傳 並 |
| GetAttributeNode(String, String) |
回傳 並 XmlAttribute 以指定的本地名稱與命名空間 URI 返回。 |
GetAttributeNode(String)
回傳 並 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 匹配節點的性質進行匹配。
傳回
XmlAttribute
null指定或未找到匹配屬性。
範例
以下範例檢查該元素是否具備指定的屬性。
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)
回傳 並 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。
傳回
XmlAttribute
null指定或未找到匹配屬性。