【发布时间】:2014-06-13 12:41:15
【问题描述】:
我必须将 xml 转换为字符串
xml被创建为:
System.Xml.Linq.XDocument doc = new System.Xml.Linq.XDocument(new System.Xml.Linq.XDeclaration("1.0", "ISO-8859-1",""));
System.Xml.Linq.XElement root = new System.Xml.Linq.XElement("qcs");
System.Xml.Linq.XElement goal_Name = new System.Xml.Linq.XElement("goal", new System.Xml.Linq.XAttribute("name","abc"));
root.Add(goal_Name);
doc.Add(root);
Console.WriteLine(doc.ToString());
我得到的字符串为:
<qcs>
<goal name="Goal15">
</goal>
</qcs>
但跳过声明部分是:
<?xml version="1.0" encoding="ISO-8859-1"?>
我需要字符串作为
<?xml version="1.0" encoding="ISO-8859-1"?>
<qcs>
<goal name="Goal15">
<value action="A">0.85</value>
<value action="B">0.87</value>
</goal>
我也需要这个字符串。 该怎么做?
【问题讨论】:
-
重复问题的链接位于帖子的顶部。
-
上面的链接没有帮助。它将字符串转换为 xml,包括声明,但它的声明为 但我想要