XNamespace.Get(String) 方法

定义

获取指定统一资源标识符 (URI) 的 XNamespaceGets an XNamespace for the specified Uniform Resource Identifier (URI).

public:
 static System::Xml::Linq::XNamespace ^ Get(System::String ^ namespaceName);
public static System.Xml.Linq.XNamespace Get (string namespaceName);
static member Get : string -> System.Xml.Linq.XNamespace
Public Shared Function Get (namespaceName As String) As XNamespace

参数

namespaceName
String

包含命名空间 URI 的 StringA String that contains a namespace URI.

返回

XNamespace

从指定的 URI 创建的 XNamespaceAn XNamespace created from the specified URI.

示例

下面的示例从指定的 URI 获取 XNamespaceThe following example gets a XNamespace from a specified URI.

XNamespace aw = XNamespace.Get("http://www.adventure-works.com");  
  
// This is the preferred form.  
XNamespace aw2 = "http://www.adventure-works.com";  
Console.WriteLine(aw);  
Console.WriteLine(aw2);  
Imports <xmlns:aw="http://www.adventure-works.com">  
  
Module Module1  
    Sub Main()  
        Dim aw As XNamespace = XNamespace.Get("http://www.adventure-works.com")  
  
        ' This is the preferred form.  
        Dim aw2 As XNamespace = GetXmlNamespace(aw)  
        Console.WriteLine(aw)  
        Console.WriteLine(aw2)  
    End Sub  
End Module  

此示例生成以下输出:This example produces the following output:

http://www.adventure-works.com  
http://www.adventure-works.com  

注解

返回的 XNamespace 对象是原子的(即,它是系统中该特定 URI 的唯一对象)。The returned XNamespace object is guaranteed to be atomic (that is, it is the only one in the system for that particular URI).

适用于

另请参阅