import System.*;
import System.IO.*;
import System.Xml.*;
public class Sample
{
public static void main(String[] args)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>"
+ "<title>Pride And Prejudice</title>"
+ "</book>");
//Create an XML declaration.
XmlDeclaration xmlDecl;
xmlDecl = doc.CreateXmlDeclaration("1.0", null, null);
//Add the new node to the document.
XmlElement root = doc.get_DocumentElement();
doc.InsertBefore(xmlDecl, root);
Console.WriteLine("Display the modified XML...");
doc.Save(Console.get_Out());
} //main
} //Sample
CreateXmlDeclaration方法
最新推荐文章于 2022-07-17 18:34:24 发布