更新时间:2021-12-13 07:56:01
这很容易使用XDocument
的流利构造函数创建格式,XElement
,...
您可以这样做:
It''s easy to create the Format using the "fluent" constructors ofXDocument
,XElement
, ...
You can do it like this:
public static XDocument CreateDocument()
{
return new XDocument(
new XElement("Body",
new XElement("getBooksResponse", new XAttribute("ns", "http://tempuri.org/"),
new XElement("getBooksResult",
new XElement("T", "book2"),
new XElement("A", "author2"),
new XElement("P", "10")
)
)
)
);
}
(如果您将属性命名为xmlns,则XML无效)
对不起,我不明白第1,2点的意思......
但我建议你使用表示数据的类层次结构,并使用 DataContractSerializer
生成XML。