[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to represent mixed content in JSON and JSON Schema?

  • From: doug.duboulay@gmail.com
  • To: xml-dev@lists.xml.org
  • Date: Thu, 12 Jul 2018 14:17:48 +0800

Re:  How to represent mixed content in JSON and JSON Schema?
I recently used pandoc to do a Latex to DocBook conversion.
    http://pandoc.org/
Turns out, IIUC, that they use a JSON representation of the document (mixed) 
content as the intermediate format for conversion between all of the target 
specifications. 
I see there is a proto schema here:
    https://gist.github.com/tarleb/bcb4b31e35263fcbc6cf7e533670c1cf

I don't know that they have an explicit slot for a bidirectional attribute, 
but since pandoc also reads DocBook  and DocBook has a "dir" attribute on some 
elements, it might be worth a  look under the hood...



On Wednesday, 11 July 2018 3:57:22 PM AWST Costello, Roger L. wrote:
> Hi Folks,
> 
> I am converting an XML Schema to a JSON Schema.
> 
> The XML Schema declares an <example> element that has bidirectional-override
> (BDO) elements intermingled with text, e.g.,
> 
> <example>Some text <bdo dir="rtl">reverse this text <bdo dir="ltr">not this
> text</bdo></bdo> finishing text</example>
> 
> rtl = right-to-left
> ltr = left-to-right
> 
> As you can see, the <example> element has mixed content, as does the <bdo>
> element.
> 
> At the bottom of this message is the XML Schema.
> 
> JSON and JSON Schema do not support mixed content, nor do they support
> attributes.
> 
> How to represent the XML in JSON and JSON Schema?
> 
> Here's what I am thinking: Mixed content is essentially an ordered sequence
> of text, element, text, element, ...
> 
> JSON arrays are intended to represent ordered sequences. So, I am thinking
> that mixed content can be represented in JSON with an array. The above
> <example> element can be expressed this way in JSON:
> 
> {
>   "example": [
>       {"text": "Some text "},
>       {"bdo":
>           [
>               {"dir": "rtl"},
>               {"text": "reverse this text "},
>               {"bdo":
>                   [
>                      {"dir": "ltr"},
>                      {"text": "not this text"}
>                   ]
>               }
>           ]
>       },
>       {"text": " finishing text"}
>   ]
> }
> 
> Notice that the content of the items with mixed content (example and bdo)
> are represented with arrays.
> 
> At the bottom of this message is the JSON Schema.
> 
> Is there a better way to represent mixed content in JSON? What makes one way
> better than another? One way can be processed easier, more efficiently than
> another?  /Roger
> 
> XML Schema
> 
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> 
>     <xs:element name="example" type="BDOMixedContent" />
> 
>     <xs:complexType name="BDOMixedContent" mixed="true">
>         <xs:choice minOccurs="0" maxOccurs="unbounded">
>             <xs:element name="bdo" type="BDOMixedContent" />
>         </xs:choice>
>         <xs:attribute name="dir">
>             <xs:simpleType>
>                 <xs:restriction base="xs:string">
>                     <xs:enumeration value="ltr" />
>                     <xs:enumeration value="rtl" />
>                 </xs:restriction>
>             </xs:simpleType>
>         </xs:attribute>
>     </xs:complexType>
> 
> </xs:schema>
> 
> 
> JSON Schema
> 
> {
>     "$schema": "http://json-schema.org/draft-07/schema#",
>     "definitions": {
>         "BDOMixedContent": {
>             "type": "array",
>             "items": {
>               "anyOf": [
>                        {
>                            "type": "object",
>                            "properties": {
>                                  "text": {"type": "string"}
>                            },
>                            "additionalProperties": false
>                        },
>                        {
>                            "type": "object",
>                            "properties": {
>                                  "bdo": {"$ref":
> "#/definitions/BDOMixedContent"} },
>                            "additionalProperties": false
>                        },
>                        {
>                            "type": "object",
>                            "properties": {
>                                  "dir": {"type": "string", "enum": ["ltr",
> "rtl"]} },
>                            "additionalProperties": false
>                        }
>                 ]
>             }
>         }
>     },
>     "type": "object",
>     "properties": {
>           "example": {"$ref": "#/definitions/BDOMixedContent"}
>     },
>     "required": [ "example" ],
>     "additionalProperties": false
> }




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.