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

Re: XML and JSON together

  • From: "bryan rasmussen" <rasmussen.bryan@g...>
  • To: rob@k...
  • Date: Tue, 8 Apr 2008 07:55:40 +0200

Re:  XML and JSON together
I guess I don't like it as a hack, it is sort of akin to the same
thing that people do when their security filters don't allow them to
send .zip files, they rename the file with a .zzz or similar extension
and then send that. If your validation is too restrictive change the
validation, furthermore I don't like it because I think it attacks the
problem from the wrong position.

 Assume you have a document with elements in the 'a' namespace, any
other namespace will be invalid, if you want to be able to send XML
with non-valid structure due to extension needs you could instead of
running a transform to expand JSON run a transform to remove all
elements in other namespaces than the 'a' namespace, or, more to the
point run a transform to extract all namespaces not in the 'a'
namespace and serialize them as their own xml instances (probably
writing rules specific to serialization of specific namespaces found)



Cheers,
Bryan Rasmussen


On Tue, Apr 8, 2008 at 12:57 AM, Robert Koberg <rob@k...> wrote:
> Hi,
>
>  Here is an odd idea I am currently playing around with. I know it is a
>  hack, but what do you think?
>
>  The idea is to use JSON to extend legacy XML instance documents while
>  maintaining original validity. For example, I have some hibernate
>  mapping documents that use the well defined DTD. I want to extend the
>  XML syntax to allow for other concerns in the mapping document which
>  will be used to generate out to multiple concerns.
>
>  With the hibernate mapping document (snippet) below I generate out a
>  java interface, a default implementation, a java 'GET' validator, a java
>  'POST' validator and a java 'POST' persistor. I can do all of that with
>  the standard mappings. But I also want to generate out a useable UI in
>  HTML. I can't do that from the standard mapping. So, I am using JSON to
>  augment the syntax while maintaining validity.
>
>  I run the mapping document through a very simple XSL 2.0 transformation
>  (even further below) that uses Dmitre Novatchev's FXSL library and
>  specifically the json-document function to create an intermediary XML
>  that is then used to generate the HTML for the form.
>
>  Here is a snippet of the mapping document:
>
>  <property column="MARRIED" length="1" name="married" not-null="true"
>  type="boolean">
>   <meta attribute="ui"><![CDATA[{
>     "uses": "focusObject",
>     "row": 1,
>     "region": "wide",
>     "legend": "Marital Status",
>     "err-msg": "Please select your marital status.",
>     "as": "radioGroup",
>     "items": {
>         "radio": {
>           "id": "marriedYes",
>           "value": true,
>           "label": "Married"
>         },
>         "radio": {
>           "id": "marriedNo",
>           "value": false,
>           "label": "Single",
>           "default": true,
>           "event": {
>             "type": "click",
>             "handler": {
>               "name": "toggle",
>               "args": {
>                 "container-idref": "domPartnerInfoCont"
>               }
>             }
>           }
>         }
>       }
>     }
>   }]]></meta>
>  </property>
>  <property column="DOMESTIC_PARTNER_INFO" name="domPartnerInfo"
>  not-null="true" type="boolean">
>   <meta attribute="ui"><![CDATA[{
>     "uses": "focusObject",
>     "row": 1,
>     "region": "wide",
>     "container-id": "domPartnerInfoCont",
>     "label": "Display Domestic Partner information?",
>     "as": "checkbox"
>   }]]></meta>
>  </property>
>
>  Running it through the json to xml transform produces:
>
>  <hibernate-ui>
>   <group column="MARRIED" length="1" name="married" not-null="true"
>  type="boolean"
>     unique="false"
>     optimistic-lock="true"
>     lazy="false"
>     generated="never">
>     <uses>focusObject</uses>
>     <row>1</row>
>     <region>wide</region>
>     <legend>Marital Status</legend>
>     <err-msg>Please select your marital status.</err-msg>
>     <as>radioGroup</as>
>     <items>
>       <radio>
>         <id>marriedYes</id>
>         <value>true</value>
>         <label>Married</label>
>       </radio>
>       <radio>
>         <id>marriedNo</id>
>         <value>false</value>
>         <label>Single</label>
>         <default>true</default>
>         <event>
>           <type>click</type>
>           <handler>
>             <name>toggle</name>
>             <args>
>               <container-idref>domPartnerInfoCont</container-idref>
>             </args>
>           </handler>
>         </event>
>       </radio>
>     </items>
>   </group>
>   <group column="DOMESTIC_PARTNER_INFO" name="domPartnerInfo"
>  not-null="true"
>     type="boolean"
>     unique="false"
>     optimistic-lock="true"
>     lazy="false"
>     generated="never">
>     <uses>focusObject</uses>
>     <row>1</row>
>     <region>wide</region>
>     <container-id>domPartnerInfoCont</container-id>
>     <label>Display Domestic Partner information?</label>
>     <as>checkbox</as>
>   </group>
>  </hibernate-ui>
>
>  And the XSL:
>
>  <?xml version="1.0" encoding="UTF-8"?>
>  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   version="2.0"
>   xmlns:xs="http://www.w3.org/2001/XMLSchema"
>   xmlns:f="http://fxsl.sf.net/"
>   exclude-result-prefixes="f xs">
>
>   <xsl:import href="fxsl-xslt2/f/func-json-document.xsl"/>
>
>   <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
>
>   <xsl:template match="/">
>     <hibernate-ui>
>       <xsl:apply-templates select="//*[meta[@attribute='ui']]"/>
>     </hibernate-ui>
>   </xsl:template>
>
>   <xsl:template match="*[meta[@attribute='ui']]">
>     <group>
>       <xsl:copy-of select="@*"/>
>       <xsl:apply-templates/>
>     </group>
>   </xsl:template>
>
>   <xsl:template match="meta[@attribute='ui']">
>     <xsl:copy-of select="f:json-document(.)"/>
>   </xsl:template>
>
>  </xsl:stylesheet>
>
>
>
>
>  _______________________________________________________________________
>
>  XML-DEV is a publicly archived, unmoderated list hosted by OASIS
>  to support XML implementation and development. To minimize
>  spam in the archives, you must subscribe before posting.
>
>  [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
>  Or unsubscribe: xml-dev-unsubscribe@l...
>  subscribe: xml-dev-subscribe@l...
>  List archive: http://lists.xml.org/archives/xml-dev/
>  List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
>


[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.