JSON inside XML

11,634

There is no "XYZ specification" per say. Though I would recommend reading up on XML and its specification because you will need to take into consideration of escaping the following characters inside your JSON for things to work nicely with XML parsers.

XML escape characters.
"   "
'   '
<   &lt;
>   &gt;
&   &amp;

or use

<![CDATA[ ]]>
Share:
11,634
hiddenuser
Author by

hiddenuser

Updated on June 14, 2022

Comments

  • hiddenuser
    hiddenuser over 1 year

    I want to know about standard and best practice in :

    Case Scenario :

    If a xml standard exist by "XYZ SPECIFICATION" (ex : BPMN Specification) like :

    <home>
    <person name="ZEN" />
    <person name="PAUL" />
    <animal name="DOG" />
    <animal name="CAT" />
    </home>
    

    and "XYZ SPECIFICATION" also provide extension element to define your own tag like :

       <home>
        <person name="ZEN" />
        <person name="PAUL" />
        <animal name="DOG" />
        <animal name="CAT" />
        <extension>
        <instrument-list>
        <type name="acoustic">
          <instrument name="GUITAR" />
          <instrument name="VIOLIN"  />
        </type>
        <type name="electronic">
          <instrument name="GUITAR" />
          <instrument name="VIOLIN"/>
        </type>
        </instrument-list>
        </extension>
        </home>
    

    Tag defined by standard are used by other client parser , they don't need to parse extension tag so i was thinking that it would be better to compress extension element using json (because json takes less space in compare to xml) :

      <home>
        <person name="ZEN" />
        <person name="PAUL" />
        <animal name="DOG" />
        <animal name="CAT" />
        <extension>
        <instrument-list>{"type":[{"name":"acoustic","instrument":[{"name":"GUITAR"},{"name":"VIOLIN"}]},{"name":"electronic","instrument":[{"name":"GUITAR"},{"name":"VIOLIN"}]}]}</instrument-list>
        </extension>
        </home>
    

    or

    <home>
        <person name="ZEN" />
        <person name="PAUL" />
        <animal name="DOG" />
        <animal name="CAT" />
        <extension>
        <instrument-list><![CDATA[ {"type":[{"name":"acoustic","instrument":[{"name":"GUITAR"},{"name":"VIOLIN"}]},{"name":"electronic","instrument":[{"name":"GUITAR"},{"name":"VIOLIN"}]}]} ]]></instrument-list>
        </extension>
        </home>
    

    Is it violates standard and best practices ?