2016-02-03 63 views

回答

0

你可以使用XmlWriterSettings並設置OmitXml聲明爲true:

XmlWriterSettings settings = new XmlWriterSettings(); 
settings.Indent = true ; 
settings.OmitXmlDeclaration = true ; 
settings.NewLineOnAttributes = true ; 

writer = XmlWriter.Create (Console.Out, settings); 

writer.WriteStartElement ("order"); 
writer.WriteAttributeString ("orderID" , "367A54"); 
writer.WriteAttributeString ("date" , "2001-05-03"); 
writer.WriteElementString ("price" , "19.95"); 
writer.WriteEndElement(); 

writer.Flush(); 

會生成:

<order 
    orderID = "367A54" 
    date = "2001-05-03"> 
    <price> 19.95 </price> 
    </order> 
相關問題