说明:使用的是Linq to xml的方式创建xml的
string internalSubset = @"<!ELEMENT Pubs (Book+)> <!ELEMENT Book (Title, Author)> <!ELEMENT Title (#PCDATA)> <!ELEMENT Author (#PCDATA)>"; string target = "xml-stylesheet"; string data = "href='mystyle.css' title='Compact' type='text/css'"; XDocument doc = new XDocument( new XComment("This is a comment."), new XProcessingInstruction(target, data), new XDocumentType("Pubs", null, null, internalSubset), new XElement("Pubs", new XElement("Book", new XElement("Title", "Artifacts of Roman Civilization"), new XElement("Author", "Moreno, Jordao") ), new XElement("Book", new XElement("Title", "Midieval Tools and Implements"), new XElement("Author", "Gazit, Inbar") ) ), new XComment("This is another comment.") ); doc.Declaration = new XDeclaration("1.0", "utf-8", "true"); Console.WriteLine(doc); doc.Save("test.xml");
本文介绍了一种使用Linq to XML创建XML文件的方法。示例中包含了如何定义内部子集、添加注释、处理指令及声明等。通过具体代码展示了如何组织XML文档结构,并保存为文件。
3562

被折叠的 条评论
为什么被折叠?



