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