I'm trying to create a Peppol Invoice xml by using C# XmlSerializer. This all works fine except for the namespaces.
The Peppol standard format has namespaces in the XmlRoot, but also in one of the XmlElements.
Xml example
<?xml version="1.0" encoding="UTF-8"?>
<StandardBusinessDocument xmlns="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
<StandardBusinessDocumentHeader>
...
</StandardBusinessDocumentHeader>
<Invoice
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ccts="urn:un:unece:uncefact:documentation:2"
xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2"
xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
</Invoice>
</StandardBusinessDocument>
If I add all namespaces with XmlSerializerNamespaces, all these namespaces are assigned to 'StandardBusinessDocument '
Code example:
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("cac", "aaa");
ns.Add("cbc", "bbb");
ns.Add("ccts", "ccc");
XmlSerializer serializer = new XmlSerializer(data.GetType());
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, data, ns);
return writer.ToString();
}
Is there any way to add these namespaces to the Invoice XmlElement?
Thanks in advance