-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XML template is more for green field devices #139
Comments
The current algorithm is essentially inspired by EXI for JSON. It maps JSON to XML. What you are describing is mapping XML to JSON.
Hence, I don't think this will ever work consistently.. w.r.t. describe XML to JSON conversion I am not sure how to move on from here best. |
In my own defense I have just copied from @takuki's initial contribution and worked with XML only in configuration files and not in APIs, so I do not have a good opinion. @danielpeintner is it possible to say that we can always define a loose schema which would validate more XML payloads than intended. By the way, I had asked the JSON Schema community about documented support for such cases and the answer is no. There is a possible clean way with https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.8.5 where we can clearly say that a schema is only for this xml payload. |
I see, what if we describe a default algorithm that converts attributes/well-defined seq/xsi:type/nillable etc. and then configure it using XML protocol binding vocabulary terms? For example:
{
"hasFoo" : true
"node_value": 2146 // real value
}
Just some additional options....
yeah but this is really almost like no validation at all... it just says put everything inside a string and treat it as XML. |
Found also this document: https://www.w3.org/2011/10/integration-workshop/s/ExperienceswithJSONandXMLTransformations.v08.pdf It defines "friendly xml". maybe we can have the rule to map only "friendly XML" and fall back to string if it is unfriendly. just throwing ideas on the table... |
Many people nowadays run into the need to support JSON & XML at the same time. Even XQuery, which used a query language for XML has support for JSON nowadays. Having said that, I don't think it is possible to properly support XML validation based on JSON schema. Let me throw in another proposal. Since I believe proper XML validation needs XML schema. XSD example for a person <xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:any minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element> Would it be feasible to represent the XSD in JSON schema... such as {
"title": "Person",
"type": "string",
"format": "xml",
"format-constraints": "<xs:element name=\"person\"> ..."
} The keys Moreover, this allows to support other formats in the future also with the same principle. What do you think? |
I think it is an option. One downside that I see is that from the application point of view we are just talking about |
From the call of 15.12:
Decision: |
Let me give you some examples where I think it is difficult to represent XML as JSON. Note1: I am not saying these are good examples. I just want to show that I think XML is more expressive. In the end I don't know whether the examples I give below are good practice... I don't think so.. in most of the cases. Nillable and Type-CastsXML allows to type-cast types to a subtype. For example an Moreover, any element can be marked as nillable in an XML instance ( Simple Content with attributesXSD allows to specify simple values like a simpleValue types as integer but still have an attribute. This would need to be mapped to an object in JSON schema.
-->
The online tool converts it to
Which is surprising to me. Conflicting names (attributes vs element)
-->
Sequence of elementsIn complex types by default using xsd:sequence the order of element matters. In JSON this is not the case. Anyhow, I don't think this is a big deal.
any and anyAttributeXSD allows to specify What is not covered is the feature than |
I had to learn a bit of XML Schema to follow, so I am not sure if my answers are really correct.
My assessment of the situation: In X percent of the cases we can have a JSON Schema representation. To me that X feels like 80% but then it is my opinion with not much experience with XML-based APIs. |
In XSD you can use that for any type. With JSON schema you would need to wrap any typo in anyOf right, I think.
XSD has a type hierarchy (see https://www.w3.org/TR/xmlschema-2/#built-in-datatypes), I think JSON schema may have one for integer & number but not the rest.
An example can be any hierarchy again One can say I expect
Yes, probably.
Mhh, since JSON has no attributes this is tricky ... maybe
Agree
I know.
Essentially in XSD one can say I expect some attribute (or element). As said similar to "additionalProperties" in JSON Schema. The difference is that I can say the any MUST be of a certain namespace... e.g., the attribute must be in the context "https://w3id.org/saref#" only. Having said that, other attributes are not allowed.
I think the percentage is even higher.. but not sure either. |
Call from 02.11:
|
Some initial findings / thoughts in a Gist |
Personally I still see XML used in APIs nowadays (even though I don't have a good use-case to share). Anyhow I must admit that in most of the cases JSON is used. Does this mean allowing to describe XML payloads is no longer a valid use case? I don't think so... FYI: RAML (the API modelling language) allows for both formats, JSON and XML. |
Given that we have data mapping in our charter, I am adding selected label. |
Reviewing XML Binding template document I noticed that it is trying more to describe a way to serialize JSON data to XML rather than trying to describe existing XML documents with our data schema. Given that I can't really find any modern API that is returning XML data I think we should be more open and don't force to use a particular "serialization" pattern even for XML.
Taking for example this XML payload:
I think we can correctly map to this JSON object:
Consequently, knowing this mapping, we can define the correct data schema:
I think that giving a clear algorithm to map an XML document to a JSON document is better than the current specification, maybe we can even find something already defined. Opinions?
The text was updated successfully, but these errors were encountered: