XName.Get 메서드

정의

XName 개체를 가져옵니다.

오버로드

Get(String)

확장된 이름을 사용하여 XName 개체를 가져옵니다.

Get(String, String)

로컬 이름 및 네임스페이스를 사용하여 XName 개체를 가져옵니다.

설명

이 메서드는 확장된 XML 이름에서 만들 XName 수 있는 오버로드를 제공합니다. 형식{namespace}localnameXName 문자열 또는 네임스페이스와 로컬 이름에서 별도로 지정된 문자열을 만들 수 있습니다.

훨씬 더 일반적이고 쉽게 만들 수 있는 XName 방법은 문자열에서 암시적 변환을 사용하는 것입니다. 네임스페이스에 있는 이름을 만들기 위해 일반적인 방법은 개체와 문자열을 결합 XNamespace 할 수 있는 더하기 연산자 오버로드를 사용하는 것입니다.

자세한 내용과 예제는 C#에서 네임스페이스를 사용하여 문서를 만드는 방법을 참조하세요.

네임스페이스 사용에 대한 자세한 내용은 XML 네임스페이스 작업을 참조하세요.

XName 개체는 원자화되므로 이름이 정확히 같은 기존 XName 개체가 있는 경우 할당된 변수는 기존 변수를 참조합니다XName. 기존 XName항목이 없으면 새 항목이 만들어지고 초기화됩니다.

Get(String)

확장된 이름을 사용하여 XName 개체를 가져옵니다.

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

매개 변수

expandedName
String

{namespace}localname 형식의 확장된 XML 이름이 들어 있는 String입니다.

반환

XName

확장된 이름을 사용하여 생성한 XName 개체입니다.

예제

다음 예제에서는 이 메서드의 사용을 보여 있습니다.

XName name = XName.Get("{http://www.adventure-works.com}Root");  
XElement el = new XElement(name, "content");  
Console.WriteLine(el);  

// This is the preferred approach for specifying the XName in the  
// constructor of XElement.  
XNamespace aw = "http://www.adventure-works.com";  
XElement el2 = new XElement(aw + "Root", "content");  
Console.WriteLine(el2);  
Imports <xmlns="http://www.adventure-works.com">  

Module Module1  
    Sub Main()  
        Dim name As XName = XName.Get("{http://www.adventure-works.com}Root")  
        Dim el As XElement = New XElement(name, "content")  
        Console.WriteLine(el)  

        ' The preferred approach for specifying an XName in a namespace  
        ' for Visual Basic is to import a global namespace.  
        Dim el2 As XElement = <Root>content</Root>  
        Console.WriteLine(el2)  
    End Sub  
End Module  

이 예제는 다음과 같은 출력을 생성합니다.

<Root xmlns="http://www.adventure-works.com">content</Root>  
<Root xmlns="http://www.adventure-works.com">content</Root>  

설명

이 메서드는 만들 수 있는 오버로드를 XName포함합니다. 폼 {namespace}localname의 확장된 XML 이름 또는 네임스페이스와 로컬 이름에서 별도로 지정하여 만들 수 있습니다.

훨씬 더 일반적이고 쉽게 만들 수 있는 XName 방법은 문자열에서 암시적 변환을 사용하는 것입니다.

XName 원자화되므로 정확히 동일한 이름의 기존 XName 항목이 있는 경우 할당된 변수는 기존 변수를 참조합니다XName. 기존 XName항목이 없으면 새 항목이 만들어지고 초기화됩니다.

추가 정보

적용 대상

Get(String, String)

로컬 이름 및 네임스페이스를 사용하여 XName 개체를 가져옵니다.

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

매개 변수

localName
String

정규화되지 않은 로컬 이름입니다.

namespaceName
String

XML 네임스페이스입니다.

반환

XName

지정된 로컬 이름 및 네임스페이스를 사용하여 만든 XName 개체입니다.

예제

다음 예제에서는 이 메서드의 사용을 보여 있습니다.

XName name = XName.Get("Root", "http://www.adventure-works.com");  
XElement el = new XElement(name, "content");  
Console.WriteLine(el);  

// This is the preferred form.  
XNamespace aw = "http://www.adventure-works.com";  
XElement el2 = new XElement(aw + "Root", "content");  
Console.WriteLine(el2);  
Imports <xmlns="http://www.adventure-works.com">  

Module Module1  
    Sub Main()  
        Dim name As XName = XName.Get("{http://www.adventure-works.com}Root")  
        Dim el As XElement = New XElement(name, "content")  
        Console.WriteLine(el)  

        ' The preferred approach for specifying an XName in a namespace  
        ' for Visual Basic is to import a global namespace.  
        Dim el2 As XElement = <Root>content</Root>  
        Console.WriteLine(el2)  
    End Sub  
End Module  

이 예제는 다음과 같은 출력을 생성합니다.

<Root xmlns="http://www.adventure-works.com">content</Root>  
<Root xmlns="http://www.adventure-works.com">content</Root>  

설명

이 메서드는 만들 수 있는 오버로드를 XName포함합니다. 폼 {namespace}localname의 확장된 XML 이름 또는 별도로 지정된 네임스페이스와 로컬 이름에서 만들 수 있습니다.

훨씬 더 일반적이고 쉽게 만들 수 있는 XName 방법은 문자열에서 암시적 변환을 사용하는 것입니다.

XName 원자화되므로 정확히 동일한 이름의 기존 XName 항목이 있는 경우 할당된 변수는 기존 변수를 참조합니다XName. 기존 XName항목이 없으면 새 항목이 만들어지고 초기화됩니다.

추가 정보

적용 대상