我正在尝试使用C#XmlSerializer创建Peppol发票xml。 除名称空间外,所有其他方法都工作正常。
Peppol标准格式在XmlRoot中具有名称空间,但在XmlElement之一中也具有名称空间。
Xml示例
<?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>
如果我使用XmlSerializerNamespaces添加所有名称空间,则所有这些名称空间均分配给'StandardBusinessDocument'
代码示例:
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();
}
是否可以将这些名称空间添加到发票XmlElement?
预先感谢