替换双引号。将字符串 "<?xml 替换为 <?xml

Replace double quote .Replace string "<?xml with <?xml

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

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

您可以使用 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>