[英]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.