[英]XDocument Namespace on root and first child
I'm building an xml file using XDocument 我正在使用XDocument构建xml文件
XDocument single = new XDocument(
new XDeclaration("1.0", "UTF-8", "true"),
new XElement(_namespace + "vcards",
XElement.Parse(BuildCardEntry(contact))));
Inside BuildCardEntry(contact)
I'm adding the namespace to every XElement
too. 在
BuildCardEntry(contact)
内部,我也将命名空间添加到每个XElement
。 But my code pruduces this 但是我的代码可以做到这一点
<vcards xmlns="urn:ietf:params:xml:ns:vcard-3.0">
<vcard xmlns="urn:ietf:params:xml:ns:vcard-3.0">
insted of this 对此感兴趣
<vcards xmlns="urn:ietf:params:xml:ns:vcard-3.0">
<vcard>
Does somebody know, how to solve this? 有人知道,如何解决这个问题?
保存xml时,请使用SaveOptions.OmitDuplicateNamespaces
参数。
single.Save(..., SaveOptions.OmitDuplicateNamespaces);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.