Replies: 1 comment
-
This does look like a reasonably straightforward translation into RDF/XML, but it's definitely way verbose. If I were doing this in a bespoke manner, I'd probably do:
<kdl:document>
<kdl:node name="package">
<kdl:node name="name">
<kdl:attr type="string">my-pkg</kdl:attr>
</kdl:node>
<kdl:node name="version">
<kdl:attr type="string">1.2.3</kdl:attr>
</kdl:node>
<kdl:node name="dependencies">
<kdl:node name="lodash">
<kdl:attr type="string">^3.2.1</kdl:attr>
<kdl:prop name="optional" type="true" />
<kdl:prop name="alias" type="string">underscore</kdl:prop>
</kdl:node>
</kdl:node>
<kdl:node name="scripts">
<kdl:node name="build">
<kdl:attr type="string">
echo "foo"
node -c "console.log('hello, world!');"
echo "foo" > some-file.txt
</kdl:attr>
</kdl:node>
<kdl:node name="the-matrix">
<kdl:attr type="number">1</kdl:attr>
<kdl:attr type="number">2</kdl:attr>
<kdl:attr type="number">3</kdl:attr>
<kdl:attr type="number">4</kdl:attr>
<kdl:attr type="number">5</kdl:attr>
<kdl:attr type="number">6</kdl:attr>
<kdl:attr type="number">7</kdl:attr>
<kdl:attr type="number">8</kdl:attr>
<kdl:attr type="number">9</kdl:attr>
</kdl:node>
</kdl:node>
</kdl:document> This is still way more verbose than the KDL, of course, due to the data model mismatches and general syntax, but way less verbose and more straightforward than the RDF version. Tags just go on as another attribute on whatever element is needed. And similar in JSON: [{"name": "package",
"nodes": [
{"name":"name", "attrs": ["my-pkg"]},
{"name":"version", "attrs": ["1.2.3"]},
{"name":"dependencies", "nodes": [
{"name": "lodash", "attrs": ["^3.2.1"], "props": {"optional": true, "alias": "underscore"} },
]},
{"name":"scripts", "nodes": [
{"name":"build", "attrs": ["\n echo \"foo\"\n node -c \"console.log('hello, world!');\"\n echo \"foo\" > some-file.txt\n "]},
]},
{"name":"the-matrix", "attrs": [1, 2, 3, 4, 5, 6, 7, 8, 9]},
],
}] Since the data models overlap this one's way more straightforward. Tagged nodes would just be a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There are more tools for working with XML than there are for KDL, so sometimes one must convert KDL to XML. This is a problem, because the KDL specification only provides a transformation from XML to KDL, and not the other way around.
One trivial solution to this problem is to represent the KDL data model in RDF, and then serialize that RDF as RDF/XML. I’ve put together a vocabulary for doing just that: https://ns.1024.gdn/KDL/. It may also help to clarify some aspects of the KDL data model (#225). Constructive feedback welcome.
The resulting transformation is not human‐friendly (the KDL original is best for that), but it is easy to manipulate with computers.
JSON lovers: The above applies just as easily, replacing RDF/XML with JSON‐LD (although tools for querying JSON are typically not as robust as, say, XPath). A context for that is provided as well.
Beta Was this translation helpful? Give feedback.
All reactions