Tuesday, July 5, 2011

XSD is a cruel joke

In an attempt to both support phy-neutral plugins dynamically adding logging attributes to the XML and supporting proper validation, the only reasonable path is XSD schemas with namespaces.  For something so extensively documented, it's very difficult to properly comprehend.

Amazingly, it looks like it IS possible to define relatively dynamic schemas, extend existing common elements, and still validate.




<k:run xmlns:k="http://www.kismetwireless.net/xml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:phy80211="http://www.kismetwireless.net/xml/phy80211" xsi:schemaLocation="http://www.kismetwireless.net/xml kismet.xsd">

<captureSource>
 <uuid>abcd</uuid>
 <definition>something</definition>
 <name>somesource</name>
 <interface>wlan0</interface>
 <type>mac80211</type>
 <packets>1234</packets>
 <channels>1,2,3,4</channels>
 <channelhop>true</channelhop>
</captureSource>

<device>
 <deviceMac>aa:bb:cc:dd:ee:ff</deviceMac>
 <gpsAverage>
        <latitude>10</latitude>
        <longitude>100</longitude>
        <altitude>50</altitude>
 </gpsAverage>

 <frequencySeen frequencyMhz="1234">10</frequencySeen>
 <frequencySeen frequencyMhz="1235">11</frequencySeen>
 <frequencySeen frequencyMhz="1236">12</frequencySeen>
</device>

<device xsi:type="phy80211:phy80211device">
 <deviceMac>11:22:33:44:55:66</deviceMac>
 <frequencySeen frequencyMhz="1234">10</frequencySeen>
 <ssid>some ssid</ssid>
</device>

</k:run>

Using multiple schemas inherited in the base xsd (not sure yet how to handle dynamics here...)

<xs:schema 
        xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        xmlns="http://xmlns.myexample.com/version3" 

        targetNamespace="http://www.kismetwireless.net/xml" 
        xmlns:common="http://www.kismetwireless.net/xml/common" 
        xmlns:device="http://www.kismetwireless.net/xml/device"

        xmlns:phy80211="http://www.kismetwireless.net/xml/phy80211"

        elementFormDefault="unqualified"
        attributeFormDefault="unqualified">

        <xs:import
                namespace="http://www.kismetwireless.net/xml/common"
                schemaLocation="./common.xsd"/>

        <xs:import
                namespace="http://www.kismetwireless.net/xml/device"
                schemaLocation="./device.xsd"/>

        <xs:import
                namespace="http://www.kismetwireless.net/xml/phy80211"
                schemaLocation="./phy80211.xsd"/>

<xs:element name="run">
 <xs:complexType>
  <xs:sequence>

   <xs:element name="captureSource" minOccurs="1" maxOccurs="unbounded" type="common:source"/>

   <xs:element name="device" maxOccurs="unbounded" type="device:device"/>

  </xs:sequence>
 </xs:complexType>
</xs:element>

</xs:schema>

XSD files (in progress):
Kismet aggregate
Common components
Device records
Phy-neutral 802.11 overlay
Example XML file for validation testing

No comments:

Post a Comment