XElement.Attribute(XName) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce l'oggetto di che XAttribute ha l'oggetto XElement specificatoXName.
public:
System::Xml::Linq::XAttribute ^ Attribute(System::Xml::Linq::XName ^ name);
public System.Xml.Linq.XAttribute Attribute(System.Xml.Linq.XName name);
public System.Xml.Linq.XAttribute? Attribute(System.Xml.Linq.XName name);
member this.Attribute : System.Xml.Linq.XName -> System.Xml.Linq.XAttribute
Public Function Attribute (name As XName) As XAttribute
Parametri
- name
- XName
Oggetto XName dell'oggetto XAttribute da ottenere.
Valori restituiti
Oggetto XAttribute con l'oggetto specificato XName; null se non è presente alcun attributo con il nome specificato.
Esempio
Nell'esempio seguente viene creato un elemento con un attributo . Recupera quindi l'attributo usando questo metodo.
XElement xmlTree = new XElement("Root",
new XAttribute("Att", "attribute content")
);
XAttribute att = xmlTree.Attribute("Att");
Console.WriteLine(att);
Dim xmlTree As XElement = <Root Att="attribute content"/>
Dim att As XAttribute = xmlTree.Attribute("Att")
Console.WriteLine(att)
In questo esempio viene generato l'output seguente:
Att="attribute content"
Di seguito è riportato lo stesso esempio, ma in questo caso il codice XML si trova in uno spazio dei nomi . Per altre informazioni, vedere Usare spazi dei nomi XML.
XNamespace aw = "http://www.adventure-works.com";
XElement xmlTree = new XElement(aw + "Root",
new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),
new XAttribute(aw + "Att", "attribute content")
);
XAttribute att = xmlTree.Attribute(aw + "Att");
Console.WriteLine(att);
Imports <xmlns:aw="http://www.adventure-works.com">
Module Module1
Sub Main()
Dim xmlTree As XElement = <aw:Root aw:Att="attribute content"/>
Dim att As XAttribute = xmlTree.Attribute(GetXmlNamespace(aw) + "Att")
Console.WriteLine(att)
End Sub
End Module
In questo esempio viene generato l'output seguente:
aw:Att="attribute content"
Commenti
Alcuni metodi dell'asse restituiscono raccolte di elementi o attributi. Questo metodo restituisce solo un singolo attributo. In alcuni casi si tratta di un singleton (a differenza di una raccolta).
Visual Basic gli utenti possono usare l'asse degli attributi integrato per recuperare il valore di un attributo con un nome specificato.