XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Understanding the scope of XML catalog


On 02.03.2019 14:38, G. Ken Holman wrote:
I wonder if Norm could be convinced to consider broadening the scope in a new XML Catalog 1.2?
But even if he conceived such a namespace URI to schema location mapping, validating parsers still need to be instructed to use the mapping.

But since you mention Norm: He happens to be the editor of the XProc specs and the author of the XProc processor XML Calabash.

With the catalog entry that you suggested, and with a small XProc pipeline, we can actually resolve the namespace URI of the top-level UBL document element to the corresponding schema!

This goes into the catalog that Calabash uses:

<uri name="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
uri="../maindoc/UBL-Invoice-2.2.xsd"/>

The XML catalog is in the file xmlcatalog/catalog.xml, which is supplied to Calabash as seen in this front-end bash script for invoking Calabash: https://github.com/transpect/calabash-frontend/blob/master/calabash.sh

In addition to the invoice schema in maindoc/, there is a mirror of the https://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/common/ directory alongside maindoc/

This is ublval.xpl:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"; version="1.0">
<p:input port="source" sequence="true" primary="true"/>
<p:output port="result" sequence="true" primary="true"/>

<p:for-each name="validation-iteration">
<p:load name="load-schema">
<p:with-option name="href" select="namespace-uri(/*)"/>
</p:load>
<p:sink/>
<p:validate-with-xml-schema assert-valid="true">
<p:input port="source">
<p:pipe port="current" step="validation-iteration"/>
</p:input>
<p:input port="schema">
<p:pipe port="result" step="load-schema"/>
</p:input>
</p:validate-with-xml-schema>
</p:for-each>

</p:declare-step>

This is an input document:

<Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 ../maindoc/UBL-Invoice-2.2.xsd"
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">
<cbc:UBLVersionID>2.2</cbc:UBLVersionID>
<cbc:ID>TOSL108</cbc:ID>
<cbc:IssueDate>2009-12-15</cbc:IssueDate>
<cac:AccountingSupplierParty/>
<cac:AccountingCustomerParty/>
<cac:PayeeParty/>
<cac:BuyerCustomerParty/>
<cac:SellerSupplierParty/>
<cac:TaxRepresentativeParty/>
<cac:Delivery/>
<cac:DeliveryTerms/>
<cac:PaymentMeans>
<cbc:PaymentMeansCode/>
</cac:PaymentMeans>
<cac:PaymentTerms/>
</Invoice>

This is the XML Calabash invocation (using the front-end bash script linked above):

calabash/calabash.sh -i source=invoice.xml ublval.xpl

This is the result:

ERROR: err:XC0053:XProc error err:XC0053
ERROR: cause: cvc-complex-type.2.4.b: The content of element 'Invoice' is not complete. One of '{"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":PaymentTerms, "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":PrepaidPayment, "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":AllowanceCharge, "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":TaxExchangeRate, "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":PricingExchangeRate, "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":PaymentExchangeRate, "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":PaymentAlternativeExchangeRate, "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":TaxTotal, "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":WithholdingTaxTotal, "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2":LegalMonetaryTotal}' is expected.
ERROR: It is a dynamic error if the assert-valid option is true and the input document is not valid.

If you don’t want the XML validation to fail but to issue a report, you can use p:try/p:catch. I can send you a more elaborate pipeline if you like.

The main trick is: In XProc, but also in other scripting languages that provide the XPath function namespace-uri(), you can read the namespace URI of the top-level element and, thanks to the catalog, resolve it immeadiately to a local copy of your schema.

You are welcome.

Gerrit


--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit.imsieke@le-tex.de, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschäftsführer / Managing Directors:
Gerrit Imsieke, Svea Jelonek, Thomas Schmidt


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS