Try this:
var serializer = new XmlSerializer( this.GetType(), null, null, new XmlRootAttribute( "PrintRequest" ), "my namespace..." );
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Actually I transform an object to a XDocument with this function
public XDocument ToXDocument()
{
var xDocSerialized = new XDocument();
using (var writer = xDocSerialized.CreateWriter())
{
var serializer = new XmlSerializer(this.GetType(), new XmlRootAttribute("PrintRequest"));
serializer.Serialize(writer, this);
}
return xDocSerialized;
}
It is possible to add a xmlns in the process ?
I found this page, but it means cloning all XDocument again...
Try this:
var serializer = new XmlSerializer( this.GetType(), null, null, new XmlRootAttribute( "PrintRequest" ), "my namespace..." );
Hi @Olivier Voutat ,
You can also change the namespace of the root element via following code:
XNamespace xmlns = "your XNamespace string";
XDocument.Root.Name = xmlns + XDocument.Root.Name.LocalName;
More details please refer to this thread.
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.