替换双引号。用<?xml替换字符串&#34; <! - ?xml

时间:2016-02-03 18:23:05

标签: c# asp.net c#-4.0 c#-3.0

这是我通过代码创建的XML文件。我想用空格或空格替换起始引号。

"<?xml version="1.0" encoding="utf-8"?>

1 个答案:

答案 0 :(得分: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>