Giter Site home page Giter Site logo

delphi-xmldoc-patch's Introduction

Introduction

This project attempt to patch native Delphi XML library that not fully support namespace in XML document.

Requirements

The project is a TestInsight DUnit project. It requires these external library:

The project use UBL-Invoice-2.1.xsd as example.

Solution

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.

Known problems

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>
  1. XML attributes defined not rendered by XML Data Binding Wizard.

delphi-xmldoc-patch's People

Contributors

ccy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.