[Message Prev][Message
Next][Thread Prev][Thread Next][Message
Index][Thread Index]
Re: xAP and XML
- Subject: Re: xAP and XML
- From: Michael McSharry
- Date: Wed, 17 Mar 2004 16:12:00 +0000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<DIV><FONT face="Arial" size="2">When I
first looked at XAP a few months back my initial though that for the most
part XAP was a document (message) exchange definition and it would seem
that use of XML would be more mainstream and flexible. I like the
idea of using XML.</FONT></DIV>
<DIV><FONT face="Arial"
size="2"></FONT> </DIV>
<DIV><FONT face="Arial"
size="2">Does the proposal that is being foreshadowed
change the header/body structure of an XAP message or is it one
where tools are being introduced so an XAP
node can translate between XAP schema using XML
technologies?</FONT></DIV>
<BLOCKQUOTE>
<DIV>----- Original Message ----- </DIV>
<DIV><B>From:</B> <A title="patrick@xxxxxxx"
href="mailto:patrick@xxxxxxx">Patrick
Lidstone (Personal E-mail)</A> </DIV>
<DIV><B>To:</B> <A
title="xAP_developer@xxxxxxx" href="mailto:xAP_developer@xxxxxxx">xAP_developer@xxxxxxx</A>
</DIV>
<DIV><B>Sent:</B> Wednesday, March 17, 2004 6:44
AM</DIV>
<DIV><B>Subject:</B> [xAP_developer] xAP and
XML</DIV>
<DIV></DIV><TT>Edward and myself have had a bit of
discussion off-list about the use ofXML, XSDs and XSLTs with xAP, and the
results are quite interesting so Ithought it might be worth a post here.
For those not familiar with thetechnology, XML is basically a
"document" (message), XSD's are a grammarfor documents, allowing
validation or composition of a document in agiven structure (schema), and
XSLT's can be applied to XML to changetheir appearance (make a mapping).xAP
control often seems to centre around receiving a message from onedevice,
extracting a value (perhaps conditionally), and then passingthat on in a
different schema to another device. XML and XSLT make thisparticularly
easy, without the need to write "real" code, and thevarious
framework developers (OK Stuart, and me, to a lesser extent)could
potentially expose a transformation framework to third party usersif there
was sufficient interest.Edward has also invested a whole lot of time in
writing an XSD toval
idate xAP messages. I'll leave it to him to upload this to the filesarea.In
the meantime, here is a quick summary of how you can use the processto do
mapping from one form to another. Although not included in thisexample,
it's possible to make individual mappings conditional, and todo basic
formatting/processing on them at mapping time. I'm quiteexcited by the
potential of this technology!Any comments/feeback/thoughts most
welcome!Patrick--- XSLT example ---The first thing I have done is written a
simple parser which convertsany xAP message into XML. Nice and easy. For
example, this message:xap-header { v=12 hop=1 uid=FF123400
class=xap-x10.request source=acme.my.controller target=rocket.cm12u.home
}xap-x10.request { command=off device=E1 } Looks like this in XML:<?xml
version="1.0"?><xapmsg> <section
name="xap-header">
<item
name="v"
value="12"/>  
; <item name="hop"
value="1"/>
<item name="uid"
value="FF123400"/>
<item name="class"
value="xap-x10.request"/>
<item name="source"
value="acme.my.controller"/>
<item name="target"
value="rocket.cm12u.home"/></section><section
name="xap-x10.request">
<item name="command"
value="off"/>
<item name="device"
value="E1"/></section></xapmsg>By applying a
stylesheet to this XML, we can transform the originaldocument (message)
into anything we want. This is really nice - it'srelatively easy to apply
complex lo
gic to the message, and could formthe basis of a nice rules engine - but in
this case all we want to do ismap my X10 schema to another
"random" schema message.Here is a simple example XSLT just to
give a flavour. The first bitcopies the header verbatim, the second bit
remaps the "command=off" bitto a new field called value which is
represented numerically (0=off).------------------<?xml
version="1.0"?><xsl:stylesheet xmlns:xsl="<A
href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"version="1.0"><xsl:template
match="/"><xapmsg><xsl:copy-of select=
"/xapmsg/section[@name='xap-header']" /><section
name="another-message"><xsl:if
test="//section[@name='xap-x10.request']/item[@name='command']/@value=
'off'"><xsl:element
name = "item"
>name='value'value='0'</xsl:element></xsl:if><xsl:if
test="//section[@name='xap-x10.request']/item[@name='command']/@value=
'on'"><xsl:element name = "item"
>name='value'value='1'</xsl:element></xsl:if></section></xapmsg></xsl:template>--------------------The
bits with // and @'s in them are xpath expressions. They selectvalues from
the original document, in much the same way you navigate adirectory
structure. For example //section[@name='xyz'] searches for anyoccurence of
an element called "section" which has an attribute
"name"of value "xyz" (ie. <section
name='xyz'>)The resulting XML output looks like this:<?xml
version="1.0"
encoding="UTF-16"?><xapmsg><section
name="xap-header"><item name="v"
value="12" /><item name="hop" value="1"
/><item name="uid" value=&
quot;FF123400" /><item name="class"
value="xap-x10.request" /><item name="source"
value="acme.my.controller" /><item name="target"
value="rocket.cm12u.home" /></section><section
name="another-message"><item>name='value'value='0'</item></section></xapmsg>This
can in turn be translated back into a "real" xAP message
(usingXSLT again, but that's not really important)xap-header { v=12 hop=1
uid=FF123400 class=xap-x10.request source=acme.my.controller
target=rocket.cm12u.home }another-message{ value=0} </TT>
xAP_Development Main Index |
xAP_Development Thread Index |
xAP_Development Home |
Archives Home
|