MinXML Examples

Example: Eastings and Northings

Here's a very simple example to get started, encoding National Grid Reference as a pair of integers.

<ngr easting="5336" northing="1805"/>

Example Comparing with XML

Here is an example presented first in full XML and then MinXML. 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. MinXML 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 MinXML, we can discard the prologue and DTD but will use the attributes
to represent text. Here's a possible representation.

<PARTS TITLE="Computer Parts">
   <PART>
      <ITEM NAME="Motherboard"/>
      <MANUFACTURER NAME="ASUS"/>
      <MODEL NAME="P3B-F"/>
      <COST VALUE="123.00"/>
      <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 MinXML. It is straightforward to automatically translate from JSON into MinXML; this example illustrates how that is possible. It also shows that JSON is noticeably more human-friendly
than MinXML by virtue of having more datatypes. MinXML 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">
    <constant field="debug" type="string" value="on"/>
    <object type="window">
        <constant field="title" type="string" value="Sample Konfabulator Widget"/>
        <constant field="name" type="string" value="main_window"/>
        <constant field="width" type="integer" value="500"/>
        <constant field="height" type="integer" value="500"/>
    </window>
    <object type="image">
        <constant field="src" type="string" value="Images/Sun.png"/>
        <constant field="name" type="string" value="sun1"/>
        <constant field="hOffset" type="integer" value="250"/>
        <constant field="vOffset" type="integer" value="250"/>
        <constant field="alignment" type="string" value="center"/>
    </image>
    <object type="text">
        <constant field="data" type="string" value="Click Here">
        <constant field="size" type="integer" value="36">
        <constant field="style" type="string" value="bold">
        <constant field="name" type="string" value="text1">
        <constant field="hOffset" type="integer" value="250"/>
        <constant field="vOffset" type="integer" value="100"/>
        <constant field="alignment" type="string" value="center"/>
        <constant field="onMouseUp" 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 MinXML. It illustrates
how MinXML's start+end tags are much more verbose than simple parentheses.

On the positive side, although the MinXML code is bigger, the redundancy
makes each fragment much easier to understand. Also, and more importantly,
notice how the inconsistent representation of terminals (e.g. died v.
"Dr Chan") disappears in the MinXML. This simplification and improved
uniformity is typical of MinXML and turns into simpler and more readable
code.

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