It would be really nice to be able to remove the namespace (xmlns:icls="http://www.aade.gr/myDATA/invoice/v1.0") from the classificationType attribute.
Code so far:
public XElement BuildXml() {
XNamespace ns = "http://www.aade.gr/myDATA/invoice/v1.0";
var root = new XElement(ns + "InvoicesDoc", new XAttribute("xmlns", ns));
var x = new XElement(ns + "incomeClassification",
new XElement(ns + "classificationType",
new XAttribute(XNamespace.Xmlns + "icls", ns), "somevalue"));
root.Add(x);
return root;
}
Output based on the above code:
<InvoicesDoc xmlns="http://www.aade.gr/myDATA/invoice/v1.0">
<incomeClassification>
<icls:classificationType xmlns:icls="http://www.aade.gr/myDATA/invoice/v1.0">somevalue</icls:classificationType>
</incomeClassification>
</InvoicesDoc>
Desired output should not have the namespace in the attribute:
<InvoicesDoc xmlns="http://www.aade.gr/myDATA/invoice/v1.0">
<incomeClassification>
<icls:classificationType>somevalue</icls:classificationType>
</incomeClassification>
</InvoicesDoc>
As @dbc suggested, I tried xmlTextWriter and worked fine. I built the xml line-by-line.