This project attempt to patch native Delphi XML library that not fully support namespace in XML document.
The project is a TestInsight DUnit project. It requires these external library:
The project use UBL-Invoice-2.1.xsd as example.
Delphi XML Data Binding generates .pas
file from XSD. The .pas
file don’t work well for multiple namespace defined in XSD.
Next, extract main node’s attributes contains xmlns
from XSD and add to the main xml node in .pas
using stored
attribute. For example:
[stored('''
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:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ccts="urn:un:unece:uncefact:documentation:2"
targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="2.1"
''')]
TXMLInvoiceType = class(TXMLNode, IXMLInvoiceType)
...
end;
The patch shall utilize the stored attribute to serve the xml nodes.
The XML Data Binding Wizard unable to generate code for xsd:extension
and xsd:restriction
node:
<xsd:element ref="cac:TaxTotal" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="TaxTotal" type="TaxTotalType"/> <xsd:complexType name="TaxTotalType"> <xsd:sequence> <xsd:element ref="cbc:TaxAmount" minOccurs="1" maxOccurs="1"/> <xsd:element ref="cbc:RoundingAmount" minOccurs="0" maxOccurs="1"/> <xsd:element ref="cbc:TaxEvidenceIndicator" minOccurs="0" maxOccurs="1"/> <xsd:element ref="cbc:TaxIncludedIndicator" minOccurs="0" maxOccurs="1"/> <xsd:element ref="cac:TaxSubtotal" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType>
<xsd:element name="TaxAmount" type="TaxAmountType"/> <xsd:complexType name="TaxAmountType"> <xsd:simpleContent> <xsd:extension base="udt:AmountType"/> // (1) </xsd:simpleContent> </xsd:complexType>
<xsd:complexType name="AmountType"> <xsd:simpleContent> <xsd:restriction base="ccts-cct:AmountType"> // (1) <xsd:attribute name="currencyID" type="xsd:normalizedString" use="required"> </xsd:attribute> </xsd:restriction> </xsd:simpleContent> </xsd:complexType>
<xsd:complexType name="AmountType"> <xsd:simpleContent> <xsd:extension base="xsd:decimal"> // (1) <xsd:attribute name="currencyID" type="xsd:normalizedString" use="optional"> </xsd:attribute> <xsd:attribute name="currencyCodeListVersionID" type="xsd:normalizedString" use="optional"> </xsd:attribute> </xsd:extension> </xsd:simpleContent> </xsd:complexType>
-
XML attributes defined not rendered by XML Data Binding Wizard.