Jas*_*ash 5 .net c# linq-to-xml
我想用whcih创建一个XDocument,如下所示:
<configurations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://msn.com/csl/featureConfigurationv2">
<configuration>
…
</configuration>
</configurations>
Run Code Online (Sandbox Code Playgroud)
我在添加第二个属性时遇到问题.我在尝试这个:
XYZ.Element("configurations").SetAttributeValue("xmlns", "http://msn.com/csl/featureConfigurationv2");
Run Code Online (Sandbox Code Playgroud)
但它没有添加属性.
你能建议别的吗?
试试这个方法
XNamespace ns = XNamespace.Get("http://msn.com/csl/featureConfigurationv2");
XDocument doc = new XDocument(
// Do XDeclaration Stuff
new XElement("configurations",
new XAttribute(XNamespace.Xmlns, ns),
// Do XElement Stuff
)
);
Run Code Online (Sandbox Code Playgroud)
也是这样
XNamespace ns = "http://msn.com/csl/featureConfigurationv2";
XElement configurations = new XElement(ns + "configurations",
new XAttribute("xmlns", "http://msn.com/csl/featureConfigurationv2"),
// Do XElement Stuff
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3014 次 |
| 最近记录: |