XElement.GetNamespaceOfPrefix(String) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the namespace associated with a particular prefix for this XElement.
public:
System::Xml::Linq::XNamespace ^ GetNamespaceOfPrefix(System::String ^ prefix);
public System.Xml.Linq.XNamespace GetNamespaceOfPrefix (string prefix);
public System.Xml.Linq.XNamespace? GetNamespaceOfPrefix (string prefix);
member this.GetNamespaceOfPrefix : string -> System.Xml.Linq.XNamespace
Public Function GetNamespaceOfPrefix (prefix As String) As XNamespace
- prefix
- String
A string that contains the namespace prefix to look up.
An XNamespace for the namespace associated with the prefix for this XElement.
The following example creates an XML tree that has a namespace with an associated prefix. It then uses this method to retrieve the XNamespace for the prefix.
XElement xmlTree = XElement.Parse("<Root xmlns:aw='http://www.adventure-works.com'/>");
XNamespace awNamespace = xmlTree.GetNamespaceOfPrefix("aw");
Console.WriteLine("Namespace: {0}", awNamespace);
When using Visual Basic, you would typically use the GetXmlNamespace Operator operator, as follows
Imports <xmlns:aw="http://www.adventure-works.com">
Module Module1
Sub Main()
Dim xmlTree As XElement = <aw:Root/>
Dim awNamespace As XNamespace = GetXmlNamespace(aw)
Console.WriteLine("Namespace: {0}", awNamespace)
End Sub
End Module
This example produces the following output:
Namespace: http://www.adventure-works.com
This method looks through the XML tree for namespace attributes that are in scope for this element. Namespace prefixes are specified in namespace attributes that are in the XML tree.
Produto | Versões |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: