XML doctype eklemek istediğim bir XDocument nesnesine sahibim. Örneğin:Bir XDocument belgesine nasıl belge ekleyebilirim?
XDocument doc = XDocument.Parse("<a>test</a>");
kullanıyorum bir XDocumentType oluşturabilirsiniz:
XDocumentType doctype = new XDocumentType("a", "-//TEST//", "test.dtd", "");
Ama mevcut XDocument nasıl olduğunu başvurabilirim? (Kök öğesinden önce eklenecek XDocumentType
etmiştir)
XDocument doc = new XDocument(
new XDocumentType("a", "-//TEST//", "test.dtd", ""),
new XElement("a", "test")
);
veya XDocument.Add
kullanın::
Bu, XDocument için de geçerli midir? MSDN bağlantısı XmlDocument için işaret eder. – dtb
@dtb: öyle, ancak XDocument için MSDN'de belirtilen bulamadık. Ayrıca güncellenmiş kod ve InvalidOperationException bakın. –
Daha sonra bir XDocumentType ekleyebilirsiniz, ancak bunun 'XDocument' öğesindeki ilk öğe olduğundan emin olmanız gerekir. Bunu, xDocument.Add (documentType) 'yerine' xDocument.AddFirst (documentType) 'kullanarak yapabilirsiniz. –