|
Subject: Re: [xsl] Convert JSON to XML? From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 2 May 2025 17:32:52 -0000 |
On Fri, 2025-05-02 at 12:07 +0000, Michael B Allen ioplex@xxxxxxxxx
wrote:
>
> <address
> B street="123 Main St"
> B city="Townville"
> B state="PA"/>
A good rule of thumb for document-oriented information in XML is that
anything user-facing should be in text content, and attributes are for
"properties' of that information. This was also suggested in the SGML
standard and amplified i think in the SGML Handbook.
Let's suppose you have a town on the border between Germany and Poland,
and you need to give both names for it in the address, marking each
with its language using xml:lang. You cannot do that with attributes.
However, i do agree that there isnbt a single JSON to XML conversion.
Consider
B B "key names" {
B B B "/" : "slash",
B B B "<" : "less than",
B B B "slash" : "/",
B B "less than" : "/"
}
(the / would need to be escaped as \/ when the JSON was embedded in
JavaScript)
Are you going to try to make elements called "/" and "less than"?
Clearly not.
You can use a hybrid approach,
B B <key-names>
B B B B <json:item key="/" value="slash" />
B B B B <slash>/</slash>
B B </key-names>
but now you have something harder to process, and, worse, you might be
40 megabytes into it before you get the first json:item or json:map or
whatever, on the five thousandth run, and it didn't show up in testing
so wasn't handled....
> 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.
Here we do agree :)
liam
--
Liam Quin,B https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations: B http://www.fromoldbooks.org
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Convert JSON to XML?, Michael B Allen iopl | Thread | Re: [xsl] Convert JSON to XML?, Tony Graham tgraham@ |
| Re: [xsl] What is the correct xpath, dvint dvint@xxxxxxxx | Date | Re: [xsl] Convert JSON to XML?, Michael B Allen iopl |
| Month |