XElement.GetPrefixOfNamespace(XNamespace) Method
Definition
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 prefix associated with a namespace for this XElement.
public:
System::String ^ GetPrefixOfNamespace(System::Xml::Linq::XNamespace ^ ns);
public string GetPrefixOfNamespace (System.Xml.Linq.XNamespace ns);
public string? GetPrefixOfNamespace (System.Xml.Linq.XNamespace ns);
member this.GetPrefixOfNamespace : System.Xml.Linq.XNamespace -> string
Public Function GetPrefixOfNamespace (ns As XNamespace) As String
Parameters
- ns
- XNamespace
An XNamespace to look up.
Returns
A String that contains the namespace prefix.
Examples
The following example creates an XML tree that contains a namespace with a prefix. It then uses this method to retrieve the prefix for the namespace. Notice that this example uses the implicit conversion from string to XNamespace when calling this method.
XElement xmlTree = XElement.Parse("<Root xmlns:aw='http://www.adventure-works.com'/>");
string prefix = xmlTree.GetPrefixOfNamespace("http://www.adventure-works.com");
Console.WriteLine("Prefix: {0}", prefix);
Imports <xmlns:aw="http://www.adventure-works.com">
Module Module1
Sub Main()
Dim xmlTree As XElement = <aw:Root/>
Dim prefix As String = xmlTree.GetPrefixOfNamespace("http://www.adventure-works.com")
Console.WriteLine("Prefix: {0}", prefix)
End Sub
End Module
This example produces the following output:
Prefix: aw
Remarks
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.
If the namespace is the default namespace, and there is no prefix for the namespace, then this method returns null.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기