Sample conversion of an instance of CCTS XML to JSON format
This is not to be considered final in any way. This is an exercise
used in the prototyping of potential JSON serializations of CCTS
documents by converting their XML to JSON syntax.
Invocation parameters and input file
Use the following invocation:
saxon9he -xsl:CCTSXML2JSON.xsl
{+gc=UBL-Entities-2.1.gc}
-s:inputXML
-o:outputJSON
The +gc= argument is optional. When supplied, the
program leverages the type information available in the model definition
as required by BDNDR 1.0.
Without such information, the serialization uses anonymous typed content
and preserves the attribute names from the XML (which are assumed in all
cases to have been pre-validated with project schemas) as required by
BDNDR 1.1.
The output is simple text without XML escaping.
The output can be indented if desired; set to "no" for continuous
The name for extension content
The CCTS dictionary is expressed as a genericode file of properties such
as the example for UBL found at .
When this file is absent, the serialization presumes the use of CEFACT
Unqualified Data Type attribute names and anonymous-typed content.
Serializing the XML as JSON
Keep track of each BBIE by its XML element name in GC file
Getting started...
}]}
Handle an ABIE by grouping its members by their name
Catch an extension
Handle an ASBIE (assumed by having element children)
Handle an extension BBIE
{"
Identifier
Name
Code
Text
_": "
Handle a BBIE (assumed by having no element children)
{"
":
true
false
Indent the result if requested
Where am I in the source nesting to determine depth?
Output a newline sequence if requested
Escape JSON text on the way out
The node whose text value is to be emitted.
Interpreting the CCTS properties
Find CCTS metadata name from attribute name
Find CCTS representation term information for BBIE
A distillation of attribute and metadata information distilled from
Amount
Binary Object
Graphic
Picture
Sound
Video
Code
Date Time
Date
Time
Identifier
Indicator
Measure
Numeric
Value
Rate
Percent
Quantity
Text
Name