HydraXML Examples

Example: Eastings and Northings

Here's a very simple example to get started, encoding National Grid Reference as a pair of integers. Just to make a contrast with MinXML, we will encode the pair of coordinates as an attribute with two values. Note how the second value is supplied with '+=' to suppress duplicate checks.

<ngr coords="5336" coords+="1805"/>

Example Comparing with XML

Here is an example presented first in full XML and then HydraXML. In the first case, note the prologue and DTD, which add no real representational power, and the arbitrary use of character data to represent text. HydraXML forces the use of attributes.

<?xml version="1.0"?>
<!DOCTYPE PARTS SYSTEM "parts.dtd">
<?xml-stylesheet type="text/css" href="xmlpartsstyle.css"?>
<PARTS>
    <TITLE>Computer Parts</TITLE>
    <PART>
        <ITEM>Motherboard</ITEM>
        <MANUFACTURER>ASUS</MANUFACTURER>
        <MODEL>P3B-F</MODEL>
        <COST> 123.00</COST>
        <DESCRIPTION><![CDATA[[<to be done>]] > </DESCRIPTION>
    </PART>
</PARTS>

In HydraXML, we can discard the prologue and DTD but will use the attributes to represent text. Here's a possible representation. Note how the fields of the PART element are given names using selectors rather than having an artificial order imposed on them.

<PARTS TITLE="Computer Parts">
   <PART>
      ITEM: <ITEM NAME="Motherboard"/>
      MANUFACTURER: <MANUFACTURER NAME="ASUS"/>
      MODEL: <MODEL NAME="P3B-F"/>
      COST: <COST VALUE="123.00"/>
      DESCRIPTION: <DESCRIPTION VALUE="&lt;to be done&gt;"/>
   </PART>
</PARTS>

Example Comparing with JSON

The following example shows a widget hierarchy for Konfabulator written in both JSON and HydraXML. It is straightforward to automatically translate from JSON into HydraXML; this example illustrates how that is possible. It also shows that JSON is noticeably more human-friendly than HydraXML by virtue of having more datatypes.HydraXML is a more general but lower level format.

{"widget": {
    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    },
    "image": { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    },
    "text": {
        "data": "Click Here",
        "size": 36,
        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,
        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
    }
}}

The same text expressed as MinXML:

<object type="widget">
    debug: <constant type="string" value="on"/>
    window:
    <object>
        title: <constant type="string" value="Sample Konfabulator Widget"/>
        name: <constant type="string" value="main_window"/>
        position: <constant type="point" value="500" value+="500"/>
    </window>
    image:
    <object>
        src: <constant type="string" value="Images/Sun.png"/>
        name: <constant type="string" value="sun1"/>
        offset: <constant type="offset" value="250" value+="250"/>
        alignment: <constant field="alignment" type="string" value="center"/>
    </image>
    text:
    <object>
        data: <constant type="string" value="Click Here">
        size: <constant type="integer" value="36">
        style: <constant type="string" value="bold">
        name: <constant type="string" value="text1">
        offset: <constant type="offset" value="250" value+="100"/>
        alignment: <constant type="string" value="center"/>
        onMouseUp: <constant type="string" value="sun1.opacity = (sun1.opacity / 100) * 90;"/>
    </text>
</widget>

Example Comparing with S-Expressions

In the following example (from Gazdar/Melish, Natural Language Processing in
Lisp), we translate from Lisp S-expressions into HydraXML. It illustrates
how HydraXML's start+end tags are much more verbose than simple parentheses.

On the positive side, although the HydraXML code is bigger, the redundancy
makes each fragment much easier to understand. In addition, the use of
child-selectors avoid the need to clumsily package the head and body of
each rule in a list.

(((S) (NP VP))
 ((VP) (V))
 ((VP) (V NP))
 ((V) died)
 ((V) employed)
 ((NP) nurses)
 ((NP) patients)
 ((NP) Medicenter)
 ((NP) "Dr Chan"))
<list>
    <rule>
        head: <symbol name="S"/>
        body+: <symbol name="NP"/>
        body+: <symbol name="VP"/>
    </rule>
    <rule>
        head: <symbol name="VP"/>
        body+: <symbol name="V"/>
    </rule>
    <rule>
        head: <symbol name="VP"/>
        body+: <symbol name="V"/>
        body+: <symbol name="NP"/>
    </rule>
    <rule>
        head: <symbol name="V"/>
        body+: <item value="died"/>
    </rule>
    <rule>
        head: <symbol name="V"/>
        body+: <item value="employed"/>
    </rule>
    <rule>
        head: <symbol name="NP"/>
        body+: <item value="nurses"/>
    </rule>
    <rule>
        head: <symbol name="NP"/>
        body+: <item value="patients"/>
    </rule>
    <rule>
        head: <symbol name="NP"/>
        body+: <item value="Medicenter"/>
    </rule>
    <rule>
        head: <symbol name="NP"/>
        body+: <item value="Dr Chan"/>
    </rule>
</list>