XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS