Re: [xsl] Convert JSON to XML?

Subject: Re: [xsl] Convert JSON to XML?
From: "Peter Flynn peter@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 2 May 2025 13:37:16 -0000
On 02/05/2025 13:07, Michael B Allen ioplex@xxxxxxxxx wrote:
[...]
For example, it is commonplace to do something like the following:

<address>
 \xA0 <street>123 Main St</street>
 \xA0 <city>Townville</city>
 \xA0 <state>PA</state>
</address>

IMO the "correct" form for an XML element is to put values that are not divisible into attributes

I respectfully disagree. The canonical test is for values known or attested to be discrete (eg standard State or Country abbreviations) to be attribute values (preferably in a token list [enumerated] if possible); and values which are infinitely variable (eg street addresses) to be plain text content (PCDATA).


But it's a sliding scale and no single answer is "correct": it leaves things like city/town names, which may or may not be discrete values for the locale; and possibly street names in the same position, with house number or name being a separate attribute. And many addresses have multiple intervening (sometimes hierarchical) values like locality, townland, district, county, etc.

There is no end to the varieties of address markup, and almost every single one of them is "wrong" in some way.

which means the truly correct way to represent this data is:

<address
 \xA0 street="123 Main St"
 \xA0 city="Townville"
 \xA0 state="PA"/>

Technically possible.


Anyway, my point is that the only "correct" way to convert JSON to XML is to understand in advance which of the many XML representations is "correct" for your particular application and then write code to explicitly perform that conversion.

Best way.


Peter

Current Thread