The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024

Latest message you have seen: Re: Embedded interface to HV - C help needed by someoneadventurous


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

xAP and XML


  • Subject: xAP and XML
  • From: Patrick Lidstone \(Personal E-mail\)
  • Date: Wed, 17 Mar 2004 14:44:00 +0000

Edward and myself have had a bit of discussion off-list about the use of
XML, XSDs and XSLTs with xAP, and the results are quite interesting so I
thought it might be worth a post here. For those not familiar with the
technology, XML is basically a "document" (message), XSD's are a
grammar
for documents, allowing validation or composition of a document in a
given structure (schema), and XSLT's can be applied to XML to change
their appearance (make a mapping).

xAP control often seems to centre around receiving a message from one
device, extracting a value (perhaps conditionally), and then passing
that on in a different schema to another device. XML and XSLT make this
particularly easy, without the need to write "real" code, and the
various framework developers (OK Stuart, and me, to a lesser extent)
could potentially expose a transformation framework to third party users
if there was sufficient interest.

Edward has also invested a whole lot of time in writing an XSD to
validate xAP messages. I'll leave it to him to upload this to the files
area.

In the meantime, here is a quick summary of how you can use the process
to do mapping from one form to another. Although not included in this
example, it's possible to make individual mappings conditional, and to
do basic formatting/processing on them at mapping time. I'm quite
excited 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 converts
any 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 original
document (message) into anything we want. This is really nice - it's
relatively easy to apply complex logic to the message, and could form
the basis of a nice rules engine - but in this case all we want to do is
map my X10 schema to another "random" schema message.

Here is a simple example XSLT just to give a flavour. The first bit
copies the header verbatim, the second bit remaps the
"command=off" bit
to 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 select
values from the original document, in much the same way you navigate a
directory structure. For example //section[@name='xyz'] searches for any
occurence 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
(using
XSLT 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
}







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.