Closed timathom closed 7 years ago
From my point of view, this bug is due to an array having a non-XML name.
Could you please try adding a test for this situation?
!(json instanceof Array)
in
XsltForms_browser.json2xml = function(eltname, json, root, inarray) {
var fullname = "";
if (eltname === "________" || !(json instanceof Array) && eltname !== "" && !XsltForms_browser.json2xmlreg.test(eltname)) {
Thank you for your feedback!
Using this condition generates a new array for each nested object, but what is wanted is a single container array.
See https://github.com/AlainCouthures/xsltforms/issues/10#issuecomment-235656687 for sample JSON data.
1.
Result from adding !(json instanceof Array)
:
<?xml version="1.0" encoding="UTF-8"?>
<exml:anonymous xmlns:exml="http://www.agencexml.com/exml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:exsi="http://www.agencexml.com/exi" xmlns="">
<________ exml:fullname="@context">
<geo xsi:type="xsd:string"
>http://www.w3.org/2003/01/geo/wgs84_pos#</geo>
<void xsi:type="xsd:string">http://rdfs.org/ns/void#</void>
<foaf xsi:type="xsd:string">http://xmlns.com/foaf/0.1/</foaf>
<dcmitype xsi:type="xsd:string">http://purl.org/dc/dcmitype/</dcmitype>
<relations xsi:type="xsd:string"
>http://pelagios.github.io/vocab/relations#</relations>
<xsd xsi:type="xsd:string">http://www.w3.org/2001/XMLSchema#</xsd>
<dcterms xsi:type="xsd:string">http://purl.org/dc/terms/</dcterms>
<nm xsi:type="xsd:string">http://nomisma.org/id/</nm>
<nmo xsi:type="xsd:string">http://nomisma.org/ontology#</nmo>
<rdf xsi:type="xsd:string"
>http://www.w3.org/1999/02/22-rdf-syntax-ns#</rdf>
<crm xsi:type="xsd:string">http://www.cidoc-crm.org/cidoc-crm/</crm>
<rdfs xsi:type="xsd:string">http://www.w3.org/2000/01/rdf-schema#</rdfs>
<oa xsi:type="xsd:string">http://www.w3.org/ns/oa#</oa>
<skos xsi:type="xsd:string">http://www.w3.org/2004/02/skos/core#</skos>
<pelagios xsi:type="xsd:string"
>http://pelagios.github.io/vocab/terms#</pelagios>
</________>
<________ exml:fullname="@graph" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36</________>
<________ exml:fullname="@type" exsi:maxOccurs="unbounded"
xsi:type="xsd:string">nmo:TypeSeriesItem</________>
<________ exml:fullname="@type" exsi:maxOccurs="unbounded"
xsi:type="xsd:string"
>http://www.w3.org/2004/02/skos/core#Concept</________>
<________ exml:fullname="rdf:type" exsi:maxOccurs="unbounded"
xsi:type="xsd:string"
>http://www.w3.org/2004/02/skos/core#Concept</________>
<________ exml:fullname="skos:prefLabel" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">RIC VIII
Constantinople 36</________>
<________ exml:fullname="@language" xsi:type="xsd:string"
>en</________>
</________>
<________ exml:fullname="skos:definition" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">RIC VIII
Constantinople 36</________>
<________ exml:fullname="@language" xsi:type="xsd:string"
>en</________>
</________>
<________ exml:fullname="dcterms:source" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/ric</________>
</________>
<________ exml:fullname="nmo:representsObjectType"
exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/coin</________>
</________>
<________ exml:fullname="nmo:hasManufacture" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/struck</________>
</________>
<________ exml:fullname="nmo:hasDenomination" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/ae3</________>
</________>
<________ exml:fullname="nmo:hasMaterial" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/billon</________>
</________>
<________ exml:fullname="nmo:hasMaterial" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/ae</________>
</________>
<________ exml:fullname="nmo:hasAuthority" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/constantius_ii</________>
</________>
<________ exml:fullname="nmo:hasMint" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/constantinople</________>
</________>
<________ exml:fullname="nmo:hasRegion" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/thrace</________>
</________>
<________ exml:fullname="nmo:hasStartDate" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string"
>0337</________>
<________ exml:fullname="@type" xsi:type="xsd:string"
>http://www.w3.org/2001/XMLSchema#gYear</________>
</________>
<________ exml:fullname="nmo:hasEndDate" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string"
>0340</________>
<________ exml:fullname="@type" xsi:type="xsd:string"
>http://www.w3.org/2001/XMLSchema#gYear</________>
</________>
<________ exml:fullname="nmo:hasObverse" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36#obverse</________>
</________>
<________ exml:fullname="nmo:hasReverse" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36#reverse</________>
</________>
<________ exml:fullname="void:inDataset" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/</________>
</________>
</________>
<________ exml:fullname="@graph" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36#obverse</________>
<________ exml:fullname="nmo:hasLegend" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">FL MAX
THEO-DORAE AVG</________>
</________>
<________ exml:fullname="dcterms:description" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">Bust of
Theodora, hair elaborately dressed, wearing plain mantle and
necklace, right</________>
<________ exml:fullname="@language" xsi:type="xsd:string"
>en</________>
</________>
<________ exml:fullname="nmo:hasPortrait" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/theodora</________>
</________>
</________>
<________ exml:fullname="@graph" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36#reverse</________>
<________ exml:fullname="nmo:hasLegend" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">PIETAS -
ROMANA€</________>
</________>
<________ exml:fullname="dcterms:description" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">Pietas,
draped, standing front, head right, carrying an infant at her
breast in right hand</________>
<________ exml:fullname="@language" xsi:type="xsd:string"
>en</________>
</________>
<________ exml:fullname="nmo:hasPortrait" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://collection.britishmuseum.org/id/person-institution/59792</________>
</________>
</________>
</exml:anonymous>
2.
Result from pull request:
<exml:anonymous xmlns:exml="http://www.agencexml.com/exml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:exsi="http://www.agencexml.com/exi" xmlns="">
<________ exml:fullname="@context">
<geo xsi:type="xsd:string"
>http://www.w3.org/2003/01/geo/wgs84_pos#</geo>
<void xsi:type="xsd:string">http://rdfs.org/ns/void#</void>
<foaf xsi:type="xsd:string">http://xmlns.com/foaf/0.1/</foaf>
<dcmitype xsi:type="xsd:string">http://purl.org/dc/dcmitype/</dcmitype>
<relations xsi:type="xsd:string"
>http://pelagios.github.io/vocab/relations#</relations>
<xsd xsi:type="xsd:string">http://www.w3.org/2001/XMLSchema#</xsd>
<dcterms xsi:type="xsd:string">http://purl.org/dc/terms/</dcterms>
<nm xsi:type="xsd:string">http://nomisma.org/id/</nm>
<nmo xsi:type="xsd:string">http://nomisma.org/ontology#</nmo>
<rdf xsi:type="xsd:string"
>http://www.w3.org/1999/02/22-rdf-syntax-ns#</rdf>
<crm xsi:type="xsd:string">http://www.cidoc-crm.org/cidoc-crm/</crm>
<rdfs xsi:type="xsd:string">http://www.w3.org/2000/01/rdf-schema#</rdfs>
<oa xsi:type="xsd:string">http://www.w3.org/ns/oa#</oa>
<skos xsi:type="xsd:string">http://www.w3.org/2004/02/skos/core#</skos>
<pelagios xsi:type="xsd:string"
>http://pelagios.github.io/vocab/terms#</pelagios>
</________>
<________ exml:fullname="@graph" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36</________>
<________ exml:fullname="@type" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded"
xsi:type="xsd:string">nmo:TypeSeriesItem</________>
<________ exml:fullname="________" exsi:maxOccurs="unbounded"
xsi:type="xsd:string"
>http://www.w3.org/2004/02/skos/core#Concept</________>
</________>
<________ exml:fullname="rdf:type" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded"
xsi:type="xsd:string"
>http://www.w3.org/2004/02/skos/core#Concept</________>
</________>
<________ exml:fullname="skos:prefLabel" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">RIC
VIII Constantinople 36</________>
<________ exml:fullname="@language" xsi:type="xsd:string"
>en</________>
</________>
</________>
<________ exml:fullname="skos:definition" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">RIC
VIII Constantinople 36</________>
<________ exml:fullname="@language" xsi:type="xsd:string"
>en</________>
</________>
</________>
<________ exml:fullname="dcterms:source" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/ric</________>
</________>
</________>
<________ exml:fullname="nmo:representsObjectType"
exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/coin</________>
</________>
</________>
<________ exml:fullname="nmo:hasManufacture"
exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/struck</________>
</________>
</________>
<________ exml:fullname="nmo:hasDenomination"
exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/ae3</________>
</________>
</________>
<________ exml:fullname="nmo:hasMaterial" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/billon</________>
</________>
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/ae</________>
</________>
</________>
<________ exml:fullname="nmo:hasAuthority"
exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/constantius_ii</________>
</________>
</________>
<________ exml:fullname="nmo:hasMint" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/constantinople</________>
</________>
</________>
<________ exml:fullname="nmo:hasRegion" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/thrace</________>
</________>
</________>
<________ exml:fullname="nmo:hasStartDate"
exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string"
>0337</________>
<________ exml:fullname="@type" xsi:type="xsd:string"
>http://www.w3.org/2001/XMLSchema#gYear</________>
</________>
</________>
<________ exml:fullname="nmo:hasEndDate" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string"
>0340</________>
<________ exml:fullname="@type" xsi:type="xsd:string"
>http://www.w3.org/2001/XMLSchema#gYear</________>
</________>
</________>
<________ exml:fullname="nmo:hasObverse" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36#obverse</________>
</________>
</________>
<________ exml:fullname="nmo:hasReverse" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36#reverse</________>
</________>
</________>
<________ exml:fullname="void:inDataset" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/</________>
</________>
</________>
</________>
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36#obverse</________>
<________ exml:fullname="nmo:hasLegend" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">FL
MAX THEO-DORAE AVG</________>
</________>
</________>
<________ exml:fullname="dcterms:description"
exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string">Bust
of Theodora, hair elaborately dressed, wearing plain
mantle and necklace, right</________>
<________ exml:fullname="@language" xsi:type="xsd:string"
>en</________>
</________>
</________>
<________ exml:fullname="nmo:hasPortrait" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://nomisma.org/id/theodora</________>
</________>
</________>
</________>
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://numismatics.org/ocre/id/ric.8.cnp.36#reverse</________>
<________ exml:fullname="nmo:hasLegend" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string"
>PIETAS - ROMANA€</________>
</________>
</________>
<________ exml:fullname="dcterms:description"
exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@value" xsi:type="xsd:string"
>Pietas, draped, standing front, head right, carrying an
infant at her breast in right hand</________>
<________ exml:fullname="@language" xsi:type="xsd:string"
>en</________>
</________>
</________>
<________ exml:fullname="nmo:hasPortrait" exsi:maxOccurs="unbounded">
<________ exml:fullname="________" exsi:maxOccurs="unbounded">
<________ exml:fullname="@id" xsi:type="xsd:string"
>http://collection.britishmuseum.org/id/person-institution/59792</________>
</________>
</________>
</________>
</________>
</exml:anonymous>
JSON arrays are to be converted in as many elements without any container to allow, for example, XPath predicates such as *[2] to locate the second item.
Ah, okay, that makes sense! So the proposed !(json instanceof Array)
condition is correct.
Close by a1763074e97b4675ab3291551502eee30281c547
For example, in JSON-LD, a
@graph
array can wrap a sequence of objects. Container arrays are not preserved in the currentjson2xml
serialization.