XDocument Oluşturucular

Tanım

XDocument sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

XDocument()

XDocument sınıfının yeni bir örneğini başlatır.

XDocument(Object[])

Belirtilen içerikle sınıfının yeni bir örneğini XDocument başlatır.

XDocument(XDocument)

Sınıfın XDocument yeni bir örneğini var olan XDocument bir nesneden başlatır.

XDocument(XDeclaration, Object[])

Belirtilen XDeclaration ve içeriğiyle sınıfının yeni bir örneğini XDocument başlatır.

Örnekler

Aşağıdaki örnek bir belge oluşturur ve ardından bir açıklama ve öğe ekler. Ardından sorgunun sonuçlarını kullanarak başka bir belge oluşturur.

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)  

Bu örnek aşağıdaki çıkışı oluşturur:

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

Açıklamalar

Aşırı yüklenmiş oluşturucular, yeni bir boş XDocumentoluşturmanızı; belirli bir ilk içeriğe sahip bir XDocument oluşturmanızı ve başka XDocument bir nesnenin kopyası olarak oluşturmanızı XDocument sağlar.

oluşturmanızı XDocumentgerektiren çok fazla senaryo yoktur. Bunun yerine, xml ağaçlarınızı genellikle bir XElement kök düğümle oluşturabilirsiniz. Belge oluşturmak için belirli bir gereksiniminiz yoksa (örneğin, işleme yönergelerini ve açıklamalarını en üst düzeyde oluşturmanız veya belge türlerini desteklemeniz gerektiğinden), kök düğüm olarak kullanmak XElement genellikle daha uygundur.

bir öğesinin geçerli içeriği XDocumenthakkında ayrıntılı bilgi için bkz. Geçerli XElement ve XDocument Nesnelerinin İçeriği.

XDocument()

XDocument sınıfının yeni bir örneğini başlatır.

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

Örnekler

Aşağıdaki örnek yeni bir belge oluşturur ve ardından açıklama ve öğe ekler.

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)  

Bu örnek aşağıdaki çıkışı oluşturur:

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

Açıklamalar

oluşturmanızı XDocumentgerektiren çok fazla senaryo yoktur. Bunun yerine, xml ağaçlarınızı genellikle bir XElement kök düğümle oluşturabilirsiniz. Belge oluşturmak için belirli bir gereksiniminiz yoksa (örneğin, işleme yönergelerini ve açıklamalarını en üst düzeyde oluşturmanız veya belge türlerini desteklemeniz gerektiğinden), kök düğüm olarak kullanmak XElement genellikle daha uygundur.

bir öğesinin geçerli içeriği XDocumenthakkında ayrıntılı bilgi için bkz. Geçerli XElement ve XDocument Nesnelerinin İçeriği.

Ayrıca bkz.

Şunlara uygulanır

XDocument(Object[])

Belirtilen içerikle sınıfının yeni bir örneğini XDocument başlatır.

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())

Parametreler

content
Object[]

Bu belgeye eklenecek içerik nesnelerinin parametre listesi.

Örnekler

Aşağıdaki örnek bir belge oluşturur ve ardından bir açıklama ve öğe ekler. Ardından sorgunun sonuçlarını kullanarak başka bir belge oluşturur.

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)  

Bu örnek aşağıdaki çıkışı oluşturur:

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

Açıklamalar

oluşturmanızı XDocumentgerektiren çok fazla senaryo yoktur. Bunun yerine, xml ağaçlarınızı genellikle bir XElement kök düğümle oluşturabilirsiniz. Belge oluşturmak için belirli bir gereksiniminiz yoksa (örneğin, işleme yönergelerini ve açıklamalarını en üst düzeyde oluşturmanız veya belge türlerini desteklemeniz gerektiğinden), kök düğüm olarak kullanmak XElement genellikle daha uygundur.

bir öğesinin geçerli içeriği XDocumenthakkında ayrıntılı bilgi için bkz. Geçerli XElement ve XDocument Nesnelerinin İçeriği.

Ayrıca bkz.

Şunlara uygulanır

XDocument(XDocument)

Sınıfın XDocument yeni bir örneğini var olan XDocument bir nesneden başlatır.

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)

Parametreler

other
XDocument

XDocument Kopyalanacak nesne.

Açıklamalar

Bir öğesinin derin bir kopyasını oluşturmak için bu oluşturucuyu XDocumentkullanırsınız.

Bu oluşturucu, parametresinde other belirtilen belgedeki tüm düğümleri ve öznitelikleri gezer ve yeni başlatılan XDocumentöğesini bir araya getirerek tüm düğümlerin kopyalarını oluşturur.

Ayrıca bkz.

Şunlara uygulanır

XDocument(XDeclaration, Object[])

Belirtilen XDeclaration ve içeriğiyle sınıfının yeni bir örneğini XDocument başlatır.

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())

Parametreler

declaration
XDeclaration

Belge için bir XDeclaration .

content
Object[]

Belgenin içeriği.

Örnekler

Aşağıdaki örnek, belge oluşturmak için bu oluşturucuyu kullanır.

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"))  

Bu örnek aşağıdaki çıkışı oluşturur:

<?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>  

Açıklamalar

oluşturmanızı XDocumentgerektiren çok fazla senaryo yoktur. Bunun yerine, xml ağaçlarınızı genellikle bir XElement kök düğümle oluşturabilirsiniz. Belge oluşturmak için belirli bir gereksiniminiz yoksa (örneğin, işleme yönergelerini ve açıklamalarını en üst düzeyde oluşturmanız veya belge türlerini desteklemeniz gerektiğinden), kök düğüm olarak kullanmak XElement genellikle daha uygundur.

bir öğesinin geçerli içeriği XDocumenthakkında ayrıntılı bilgi için bkz. Geçerli XElement ve XDocument Nesnelerinin İçeriği.

Ayrıca bkz.

Şunlara uygulanır