XDocument 생성자

정의

XDocument 클래스의 새 인스턴스를 초기화합니다.

오버로드

XDocument()

XDocument 클래스의 새 인스턴스를 초기화합니다.

XDocument(Object[])

지정된 콘텐츠를 사용하여 XDocument 클래스의 새 인스턴스를 초기화합니다.

XDocument(XDocument)

기존 XDocument 개체를 사용하여 XDocument 클래스의 새 인스턴스를 초기화합니다.

XDocument(XDeclaration, Object[])

지정된 XDocument 및 콘텐츠를 사용하여 XDeclaration 클래스의 새 인스턴스를 초기화합니다.

예제

다음 예제에서는 문서를 만든 다음 메모와 요소를 추가합니다. 그런 다음 쿼리 결과를 사용하여 다른 문서를 작성합니다.

XDocument srcTree = new XDocument(  
    new XComment("This is a comment"),  
    new XElement("Root",  
        new XElement("Child1", "data1"),  
        new XElement("Child2", "data2"),  
        new XElement("Child3", "data3"),  
        new XElement("Child2", "data4"),  
        new XElement("Info5", "info5"),  
        new XElement("Info6", "info6"),  
        new XElement("Info7", "info7"),  
        new XElement("Info8", "info8")  
    )  
);  

XDocument doc = new XDocument(  
    new XComment("This is a comment"),  
    new XElement("Root",  
        from el in srcTree.Element("Root").Elements()  
        where ((string)el).StartsWith("data")  
        select el  
    )  
);  
Console.WriteLine(doc);  
Dim srcTree As XDocument = _   
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>  
        <!--This is a comment-->  
        <Root>  
            <Child1>data1</Child1>  
            <Child2>data2</Child2>  
            <Child3>data3</Child3>  
            <Child2>data4</Child2>  
            <Info5>info5</Info5>  
            <Info6>info6</Info6>  
            <Info7>info7</Info7>  
            <Info8>info8</Info8>  
        </Root>  
Dim doc As XDocument = _   
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>  
        <!--This is a comment-->  
        <Root>  
            <%= From el In srcTree.<Root>.Elements _  
                Where CStr(el).StartsWith("data") _  
                Select el %>  
        </Root>  
Console.WriteLine(doc)  

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

<!--This is a comment-->  
<Root>  
  <Child1>data1</Child1>  
  <Child2>data2</Child2>  
  <Child3>data3</Child3>  
  <Child2>data4</Child2>  
</Root>  

설명

오버로드된 생성자를 사용하면 비어 XDocument있는 새 생성자를 만들 수 있습니다. 지정된 초기 콘텐츠를 사용하여 만들고 XDocument 다른 XDocument 개체의 복사본으로 만들 XDocument 수 있습니다.

XDocument를 만들어야 하는 시나리오는 많지 않습니다. 대신 일반적으로 XElement 루트 노드를 사용하여 XML 트리를 만들 수 있습니다. 문서를 만들어야 하는 특정 요구 사항(예를 들어, 최상위 수준에서 처리 명령과 주석을 만들어야 하거나 문서 형식을 지원해야 하는 경우)이 없는 한 XElement를 루트 노드로 사용하는 것이 더 편리한 경우가 많습니다.

유효한 콘텐츠 XDocument에 대한 자세한 내용은 XElement 및 XDocument 개체의 유효한 콘텐츠를 참조하세요.

XDocument()

XDocument 클래스의 새 인스턴스를 초기화합니다.

public:
 XDocument();
public XDocument ();
Public Sub New ()

예제

다음 예제에서는 새 문서를 만든 다음 메모와 요소를 추가합니다.

XDocument doc = new XDocument();  
doc.Add(new XComment("This is a comment"));  
doc.Add(new XElement("Root", "content"));  
Console.WriteLine(doc);  
Dim doc As XDocument = New XDocument()  
doc.Add(<!--This is a comment-->)  
doc.Add(<Root>content</Root>)  
Console.WriteLine(doc)  

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

<!--This is a comment-->  
<Root>content</Root>  

설명

XDocument를 만들어야 하는 시나리오는 많지 않습니다. 대신 일반적으로 XElement 루트 노드를 사용하여 XML 트리를 만들 수 있습니다. 문서를 만들어야 하는 특정 요구 사항(예를 들어, 최상위 수준에서 처리 명령과 주석을 만들어야 하거나 문서 형식을 지원해야 하는 경우)이 없는 한 XElement를 루트 노드로 사용하는 것이 더 편리한 경우가 많습니다.

유효한 콘텐츠 XDocument에 대한 자세한 내용은 XElement 및 XDocument 개체의 유효한 콘텐츠를 참조하세요.

추가 정보

적용 대상

XDocument(Object[])

지정된 콘텐츠를 사용하여 XDocument 클래스의 새 인스턴스를 초기화합니다.

public:
 XDocument(... cli::array <System::Object ^> ^ content);
public XDocument (params object[] content);
public XDocument (params object?[] content);
new System.Xml.Linq.XDocument : obj[] -> System.Xml.Linq.XDocument
Public Sub New (ParamArray content As Object())

매개 변수

content
Object[]

이 문서에 추가할 콘텐츠 개체의 매개 변수 목록입니다.

예제

다음 예제에서는 문서를 만든 다음 메모와 요소를 추가합니다. 그런 다음 쿼리 결과를 사용하여 다른 문서를 작성합니다.

XDocument srcTree = new XDocument(  
    new XComment("This is a comment"),  
    new XElement("Root",  
        new XElement("Child1", "data1"),  
        new XElement("Child2", "data2"),  
        new XElement("Child3", "data3"),  
        new XElement("Child2", "data4"),  
        new XElement("Info5", "info5"),  
        new XElement("Info6", "info6"),  
        new XElement("Info7", "info7"),  
        new XElement("Info8", "info8")  
    )  
);  

XDocument doc = new XDocument(  
    new XComment("This is a comment"),  
    new XElement("Root",  
        from el in srcTree.Element("Root").Elements()  
        where ((string)el).StartsWith("data")  
        select el  
    )  
);  
Console.WriteLine(doc);  
Dim srcTree As XDocument = _  
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>  
        <!--This is a comment-->  
        <Root>  
            <Child1>data1</Child1>  
            <Child2>data2</Child2>  
            <Child3>data3</Child3>  
            <Child2>data4</Child2>  
            <Info5>info5</Info5>  
            <Info6>info6</Info6>  
            <Info7>info7</Info7>  
            <Info8>info8</Info8>  
        </Root>  
Dim doc As XDocument = _   
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>  
        <!--This is a comment-->  
        <Root>  
            <%= From el In srcTree.<Root>.Elements _  
                Where CStr(el).StartsWith("data") _  
                Select el %>  
        </Root>  
Console.WriteLine(doc)  

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

<!--This is a comment-->  
<Root>  
  <Child1>data1</Child1>  
  <Child2>data2</Child2>  
  <Child3>data3</Child3>  
  <Child2>data4</Child2>  
</Root>  

설명

XDocument를 만들어야 하는 시나리오는 많지 않습니다. 대신 일반적으로 XElement 루트 노드를 사용하여 XML 트리를 만들 수 있습니다. 문서를 만들어야 하는 특정 요구 사항(예를 들어, 최상위 수준에서 처리 명령과 주석을 만들어야 하거나 문서 형식을 지원해야 하는 경우)이 없는 한 XElement를 루트 노드로 사용하는 것이 더 편리한 경우가 많습니다.

유효한 콘텐츠 XDocument에 대한 자세한 내용은 XElement 및 XDocument 개체의 유효한 콘텐츠를 참조하세요.

추가 정보

적용 대상

XDocument(XDocument)

기존 XDocument 개체를 사용하여 XDocument 클래스의 새 인스턴스를 초기화합니다.

public:
 XDocument(System::Xml::Linq::XDocument ^ other);
public XDocument (System.Xml.Linq.XDocument other);
new System.Xml.Linq.XDocument : System.Xml.Linq.XDocument -> System.Xml.Linq.XDocument
Public Sub New (other As XDocument)

매개 변수

other
XDocument

복사할 XDocument 개체입니다.

설명

이 생성자를 사용하여 전체 복사본을 만듭니다 XDocument.

이 생성자는 매개 변수에 지정된 other 문서의 모든 노드와 특성을 트래버스하고 새로 초기화된 XDocument노드를 어셈블할 때 모든 노드의 복사본을 만듭니다.

추가 정보

적용 대상

XDocument(XDeclaration, Object[])

지정된 XDocument 및 콘텐츠를 사용하여 XDeclaration 클래스의 새 인스턴스를 초기화합니다.

public:
 XDocument(System::Xml::Linq::XDeclaration ^ declaration, ... cli::array <System::Object ^> ^ content);
public XDocument (System.Xml.Linq.XDeclaration declaration, params object[] content);
public XDocument (System.Xml.Linq.XDeclaration? declaration, params object[] content);
public XDocument (System.Xml.Linq.XDeclaration? declaration, params object?[] content);
new System.Xml.Linq.XDocument : System.Xml.Linq.XDeclaration * obj[] -> System.Xml.Linq.XDocument
Public Sub New (declaration As XDeclaration, ParamArray content As Object())

매개 변수

declaration
XDeclaration

문서의 XDeclaration입니다.

content
Object[]

문서의 콘텐츠입니다.

예제

다음 예제에서는 이 생성자를 사용하여 문서를 만듭니다.

XDocument srcTree = new XDocument(  
    new XComment("This is a comment"),  
    new XElement("Root",  
        new XElement("Child1", "data1"),  
        new XElement("Child2", "data2"),  
        new XElement("Child3", "data3"),  
        new XElement("Child2", "data4"),  
        new XElement("Info5", "info5"),  
        new XElement("Info6", "info6"),  
        new XElement("Info7", "info7"),  
        new XElement("Info8", "info8")  
    )  
);  

XDocument doc = new XDocument(  
    new XDeclaration("1.0", "utf-8", "yes"),  
    new XComment("This is a new comment"),  
    new XElement("Root",  
        from el in srcTree.Element("Root").Elements()  
        where ((string)el).StartsWith("data")  
        select el  
    )  
);  
doc.Save("Test.xml");  
Console.WriteLine(File.ReadAllText("Test.xml"));  
Dim srcTree As XDocument = _   
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>  
        <!--This is a comment-->  
        <Root>  
            <Child1>data1</Child1>  
            <Child2>data2</Child2>  
            <Child3>data3</Child3>  
            <Child2>data4</Child2>  
            <Info5>info5</Info5>  
            <Info6>info6</Info6>  
            <Info7>info7</Info7>  
            <Info8>info8</Info8>  
        </Root>  
Dim doc As XDocument = _   
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>  
        <!--This is a new comment-->  
        <Root>  
            <%= From el In srcTree.<Root>.Elements _  
                Where CStr(el).StartsWith("data") _  
                Select el %>  
        </Root>  
doc.Save("Test.xml")  
Console.WriteLine(File.ReadAllText("Test.xml"))  

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

<?xml version="1.0" encoding="utf-8" standalone="yes"?>  
<!--This is a new comment-->  
<Root>  
  <Child1>data1</Child1>  
  <Child2>data2</Child2>  
  <Child3>data3</Child3>  
  <Child2>data4</Child2>  
</Root>  

설명

XDocument를 만들어야 하는 시나리오는 많지 않습니다. 대신 일반적으로 XElement 루트 노드를 사용하여 XML 트리를 만들 수 있습니다. 문서를 만들어야 하는 특정 요구 사항(예를 들어, 최상위 수준에서 처리 명령과 주석을 만들어야 하거나 문서 형식을 지원해야 하는 경우)이 없는 한 XElement를 루트 노드로 사용하는 것이 더 편리한 경우가 많습니다.

유효한 콘텐츠 XDocument에 대한 자세한 내용은 XElement 및 XDocument 개체의 유효한 콘텐츠를 참조하세요.

추가 정보

적용 대상