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

XML and JSON together

  • From: Robert Koberg <rob@k...>
  • To: xml-dev <xml-dev@l...>
  • Date: Mon, 07 Apr 2008 18:57:26 -0400

XML and JSON together
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>





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