The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

RE: xAP and XML


  • Subject: RE: xAP and XML
  • From: Edward Pearson
  • Date: Wed, 17 Mar 2004 21:18:00 +0000

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<TITLE>Message</TITLE>
<DIV><SPAN class="568235420-17032004"><FONT
face="Arial" size="2">I have now uploaded my example
files mentioned below.</FONT></SPAN></DIV>
<DIV><SPAN class="568235420-17032004"><FONT
face="Arial"
size="2"></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class="568235420-17032004"><FONT
face="Arial" size="2">These
are:</FONT></SPAN></DIV>
<DIV><SPAN class="568235420-17032004"><FONT
face="Arial"
size="2"></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class="568235420-17032004">
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004">1) An XML represen<SPAN
class="568235420-17032004">t</SPAN>ation for xAP
messages. This builds on the example Partick suggested&nbsp;<SPAN
class="568235420-17032004">(</SPAN><SPAN
class="568235420-17032004">which makes explicit the simple
regular structure of xAP messages on the wire)
and</SPAN>&nbsp;adds some more robustness&nbsp;<SPAN
class="568235420-17032004">by staring to express some of the
semantic relationships between elements. Also
the&nbsp;</SPAN>explicit naming of things enables XSLT
transformations that are somewhat easier to author/read<SPAN
class="568235420-17032004"> (that's if you think any of this
stuff is easy to read)</SPAN>.</SPAN></FONT></DIV>
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004"></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004">2) An XSLT transformation that
renders&nbsp;<SPAN class="568235420-17032004">XML
</SPAN>messages<SPAN
class="568235420-17032004">&nbsp;back to
xAP</SPAN>&nbsp;for network
transmission</SPAN></FONT></DIV>
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004"></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004">3) A XSD schema for xAP
messages&nbsp;<SPAN class="568235420-17032004">in the
format of the exampe1 file </SPAN>that allows for them to be
automatically validated</SPAN></FONT></DIV>
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004"></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004">There's&nbsp;<SPAN
class="568235420-17032004">plenty </SPAN>more work to do
on the&nbsp;<SPAN
class="568235420-17032004">XSD</SPAN><SPAN
class="568235420-17032004">. For example there's
no</SPAN>&nbsp;data type validation, eg - check that a UID is
correctly formed<SPAN class="568235420-17032004">. And this
one is generic to any xAP-schema so passing validation with this will only
tell you that it's a valid xAP message not that it conforms to a particular
xAP-schema. But it shows what can be done and the potential for validating
xAP-schemas generally. One fun part is&nbsp;it a</SPAN>llows you
to write xAP-XML messages in Visu<SPAN
class="568235420-17032004">al</SPAN> Studio with
intellisense prompting.</SPAN></FONT></DIV>
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004"></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004"><SPAN
class="568235420-17032004">Edward</SPAN></SPAN></FONT></DIV>
<DIV><FONT face="Tahoma" size="2"><SPAN
class="035034023-14032004"></SPAN></FONT>&nbsp;</DIV></SPAN></DIV>
<BLOCKQUOTE>
<DIV></DIV>
<DIV class="OutlookMessageHeader" lang="en-us"
dir="ltr" align="left"><FONT
face="Tahoma" size="2">-----Original
Message-----<B>From:</B> Patrick Lidstone (Personal E-mail) [mailto:patrick@xxxxxxx]
<B>Sent:</B> 17 March 2004 14:44<B>To:</B>
xAP_developer@xxxxxxx<B>Subject:</B> [xAP_developer] xAP and
XML</FONT></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 messag
e 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 tovalidate 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. N
ice 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">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <item
name="v"
value="12"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<item name="hop"
value="1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<item name="uid"
value="FF123400"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<item name="class"
value="xap-x10.request"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<item name="source"
value="acme.my.controller"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<item name="target"
value="rocket.cm12u.home"/></section><
section
name="xap-x10.request">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<item name="command"
value="off"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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 logic 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.w
3.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'] searche
s 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="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

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.