I want to create an XDocument with whcih will look like below:
<configurations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://msn.com/csl/featureConfigurationv2">
<configuration>
…
</configuration>
</configurations>
I am facing problem in adding the second attribute. I am trying this:
XYZ.Element("configurations").SetAttributeValue("xmlns", "http://msn.com/csl/featureConfigurationv2");
But its not adding the attribute.
Can you suggest something else please.
Try this way
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
)
);
and this way too
XNamespace ns = "http://msn.com/csl/featureConfigurationv2";
XElement configurations = new XElement(ns + "configurations",
new XAttribute("xmlns", "http://msn.com/csl/featureConfigurationv2"),
// Do XElement Stuff
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With