XDocument Oluşturucular
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
XDocument sınıfının yeni bir örneğini başlatır.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| 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) |
Mevcut XDocument bir nesneden sınıfının yeni bir örneğini XDocument başlatır. |
| XDocument(XDeclaration, Object[]) |
Belirtilen XDocument ve içeriğiyle sınıfının yeni bir örneğini XDeclaration başlatır. |
Örnekler
Aşağıdaki örnek bir belge oluşturur ve sonra buna 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ıza olanak tanır; XDocument belirli bir ilk içerikle oluşturma ve başka XDocument bir nesnenin kopyası olarak oluşturmaXDocument.
oluşturmanızı XDocumentgerektiren çok fazla senaryo yoktur. Bunun yerine, xml ağaçlarınızı genellikle XElement bir 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), genellikle kök düğüm olarak kullanmak XElement 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()
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
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 sonra buna bir 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 XElement bir 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), genellikle kök düğüm olarak kullanmak XElement 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[])
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
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 sonra buna 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 XElement bir 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), genellikle kök düğüm olarak kullanmak XElement 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)
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
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
Açıklamalar
Bir derin kopyasını XDocumentoluşturmak için bu oluşturucuyu kullanırsınız.
Bu oluşturucu, parametresinde other belirtilen belgedeki tüm düğümleri ve öznitelikleri gezer ve yeni başlatılan XDocumentöğesini derlerken tüm düğümlerin kopyalarını oluşturur.
Ayrıca bkz.
Şunlara uygulanır
XDocument(XDeclaration, Object[])
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
- Kaynak:
- XDocument.cs
Belirtilen XDocument ve içeriğiyle sınıfının yeni bir örneğini XDeclaration 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 XElement bir 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), genellikle kök düğüm olarak kullanmak XElement 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.