[英]Adding xmlns namespace in an Xdocument
我想用whcih创建一个XDocument,如下所示:
<configurations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://msn.com/csl/featureConfigurationv2">
<configuration>
…
</configuration>
</configurations>
我在添加第二个属性时遇到问题。 我在尝试这个:
XYZ.Element("configurations").SetAttributeValue("xmlns", "http://msn.com/csl/featureConfigurationv2");
但它没有添加属性。
你能建议别的吗?
试试这种方式
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
)
);
这样也是
XNamespace ns = "http://msn.com/csl/featureConfigurationv2";
XElement configurations = new XElement(ns + "configurations",
new XAttribute("xmlns", "http://msn.com/csl/featureConfigurationv2"),
// Do XElement Stuff
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.