这可能是一个初学者的 xml 问题,但是如何生成如下所示的 xml 文档呢?
<root xmlns:ci="http://somewhere.com" xmlns:ca="http://somewhereelse.com">
<ci:field1>test</ci:field1>
<ca:field2>another test</ca:field2>
</root>
如果我能把这个写下来,我就能解决剩下的问题。
理想情况下,我希望将 LINQ to XML(XElement、XNamespace 等)与 c# 结合使用,但如果使用 XmlDocuments 和 XmlElements 可以更轻松/更好地完成此操作,我会选择这样做。
谢谢!!!
这是一个创建您想要的输出的小示例:
using System;
using System.Xml.Linq;
class Program
{
static void Main()
{
XNamespace ci = "http://somewhere.com";
XNamespace ca = "http://somewhereelse.com";
XElement element = new XElement("root",
new XAttribute(XNamespace.Xmlns + "ci", ci),
new XAttribute(XNamespace.Xmlns + "ca", ca),
new XElement(ci + "field1", "test"),
new XElement(ca + "field2", "another test"));
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)