Add multiple namespacs with same address to XDocument
I need to add multiple namespaces to the xdocument with same address (C#)
<root xmlns:f="urn://xml.voodoo.net/vd/formating-1.0" xmlns="urn://xml.voodoo.net/vd/formating-1.0">
<a:something>stuff and more stuff</a开发者_JAVA百科:something>
</root>
if i add using the below code.. it shows only xmlns:f
XNamespace defaultNS = "urn://xml.voodoo.net/vd/formating-1.0";
XNamespace f = "urn://xml.voodoo.net/vd/formating-1.0";
XElement rootElement = new XElement(defaultNS + "root",
new XAttribute(XNamespace.Xmlns + "f", f.NamespaceName),
how to show 2 namespaces?? is it even possible?
var doc = new XDocument(
new XElement(defaultNS + "root",
new XAttribute(XNamespace.Xmlns + "f", defaultNS),
new XAttribute("xmlns", defaultNS),
new XElement(defaultNS + "something",
new XAttribute(XNamespace.Xmlns + "f", defaultNS), "stuff and more stuff")
)
);
Desired output:
<root xmlns:f="urn://xml.voodoo.net/vd/formating-1.0" xmlns="urn://xml.voodoo.net/vd/formating-1.0">
<f:something xmlns:f="urn://xml.voodoo.net/vd/formating-1.0">stuff and more stuff</f:something>
</root>
Your XML example is incorrect, the 'f' namespace is not used, whereas there is an 'a' namespace present.
Your C# code does not match your XML, it creates an element with an attribute.
Anyhow, a namespace definitions within an XML document only makes sense if you actually use it. If you create an XML document via C# code, it will generate XML which is semantically correct, yet might not match the syntax of your example.
精彩评论