Implementing XML parsers is easy in almost any language. The work the W3C has done to produce standards and IDL is quite amazing. To give you an idea for your XML implementation however, here's an example XML save-file for a vector graphics based app I once made:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sketch SYSTEM "simplepaint.dtd">
<canvas>
<circle angle="0.0" radius="48.104053883222775">
<color B="255" G="0" R="0"/>
<position x="106.0" y="27.0"/>
</circle>
<circle angle="0.0" radius="70.21395872616783">
<color B="255" G="0" R="0"/>
<position x="246.0" y="7.0"/>
</circle>
<circle angle="0.0" radius="18.027756377319946">
<color B="0" G="0" R="255"/>
<position x="197.0" y="158.0"/>
</circle>
<text angle="0.0">
<color B="0" G="255" R="0"/>
<position x="447.0" y="149.0"/>
<font fontname="SansSerif" fontstyle="plain" pointsize="12"/>
<string>
<bounds height="12" width="80"/>
My Names Ally
</string>
</text>
<text angle="0.0">
<color B="0" G="255" R="0"/>
<position x="427.0" y="291.0"/>
<font fontname="Book Antiqua" fontstyle="bold-italic" pointsize="22"/>
<string>
<bounds height="18" width="69"/>
I smell
</string>
</text>
<circle angle="0.0" radius="183.50476833041697">
<color B="255" G="0" R="0"/>
<position x="60.0" y="-20.0"/>
</circle>
</canvas>
Here is the dtd:
Code:
<!ELEMENT canvas (line|circle|rectangle|curve|text)*>
<!ELEMENT color EMPTY>
<!ATTLIST color
R CDATA #REQUIRED
G CDATA #REQUIRED
B CDATA #REQUIRED
>
<!ENTITY % coordinates "x CDATA #REQUIRED y CDATA #REQUIRED">
<!ELEMENT position EMPTY>
<!ATTLIST position %coordinates;>
<!ELEMENT endpoint EMPTY>
<!ATTLIST endpoint %coordinates;>
<!ELEMENT line (color, position, endpoint)>
<!ATTLIST line
angle CDATA #REQUIRED
>
<!ELEMENT rectangle (color, position, bottomright)>
<!ATTLIST rectangle
angle CDATA #REQUIRED
>
<!ELEMENT bottomright EMPTY>
<!ATTLIST bottomright %coordinates;>
<!ELEMENT circle (color, position)>
<!ATTLIST circle
radius CDATA #REQUIRED
angle CDATA #REQUIRED
>
<!ELEMENT curve (color, position, point+)>
<!ATTLIST curve angle CDATA #REQUIRED>
<!ELEMENT point EMPTY>
<!ATTLIST point %coordinates;>
<!ELEMENT text (color, position, font, string)>
<!ATTLIST text angle CDATA #REQUIRED>
<!ELEMENT font EMPTY>
<!ATTLIST font
fontname CDATA #REQUIRED
fontstyle (plain|bold|italic|bold-italic) #REQUIRED
pointsize CDATA #REQUIRED
>
<!ELEMENT string (#PCDATA|bounds)*>
<!ELEMENT bounds EMPTY>
<!ATTLIST bounds
width CDATA #REQUIRED
height CDATA #REQUIRED
>
Here is the alternative XML Schema:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="canvas" type="SketchType"/>
<!--Type for a sketch root element -->
<xsd:complexType name="SketchType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="line" type="LineType" />
<xsd:element name="rectangle" type="RectangleType" />
<xsd:element name="circle" type="CircleType" />
<xsd:element name="curve" type="CurveType" />
<xsd:element name="text" type="TextType" />
</xsd:choice>
</xsd:complexType>
<!--Type for a line element -->
<xsd:complexType name="LineType">
<xsd:sequence>
<xsd:element name="color" type="ColorType" />
<xsd:element name="position" type="PointType" />
<xsd:element name="endpoint" type="PointType" />
</xsd:sequence>
<xsd:attribute name="angle" type="xsd:double" />
</xsd:complexType>
<!--Type for a rectangle element -->
<xsd:complexType name="RectangleType">
<xsd:sequence>
<xsd:element name="color" type="ColorType" />
<xsd:element name="position" type="PointType" />
<xsd:element name="bottomright" type="PointType" />
</xsd:sequence>
<xsd:attribute name="angle" type="xsd:double" />
</xsd:complexType>
<!--Type for a circle element -->
<xsd:complexType name="CircleType">
<xsd:sequence>
<xsd:element name="color" type="ColorType" />
<xsd:element name="position" type="PointType" />
</xsd:sequence>
<xsd:attribute name="radius" type="xsd:double" />
<xsd:attribute name="angle" type="xsd:double" />
</xsd:complexType>
<!--Type for a curve element -->
<xsd:complexType name="CurveType">
<xsd:sequence>
<xsd:element name="color" type="ColorType" />
<xsd:element name="position" type="PointType" />
<xsd:element name="point" type="PointType" minOccurs="1" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="angle" type="xsd:double" />
</xsd:complexType>
<!--Type for a text element -->
<xsd:complexType name="TextType">
<xsd:sequence>
<xsd:element name="color" type="ColorType" />
<xsd:element name="position" type="PointType" />
<xsd:element name="font" type="FontType" />
<xsd:element name="string" type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="angle" type="xsd:double" />
</xsd:complexType>
<!--Type for a font element -->
<xsd:complexType name="FontType">
<xsd:attribute name="fontname" type="xsd:string" use="required" />
<xsd:attribute name="fontstyle" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="plain" />
<xsd:enumeration value="bold" />
<xsd:enumeration value="italic" />
<xsd:enumeration value="bold-italic" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<!--Type for elements representing points -->
<xsd:complexType name="PointType">
<xsd:attributeGroup ref="coords" />
</xsd:complexType>
<!--Type for a color element -->
<xsd:complexType name="ColorType">
<xsd:attribute name="R" type="xsd:nonNegativeInteger" use="required" />
<xsd:attribute name="G" type="xsd:nonNegativeInteger" use="required" />
<xsd:attribute name="B" type="xsd:nonNegativeInteger" use="required" />
</xsd:complexType>
<!--Attribute group specifying point coordinates -->
<xsd:attributeGroup name="coords">
<xsd:attribute name="x" type="xsd:double" use="required" />
<xsd:attribute name="y" type="xsd:double" use="required" />
</xsd:attributeGroup>
</xsd:schema>
Personally i'm not 100% comfortable with Schemas and even the above with its extremely simple namespace can become confusing, probably because I started with dtd's and am stuck in my ways.
But still you can see how the XML file above could be loaded by the parser (using either SAX or DOM in Java, I prefer SAX for most of my work, default parser is xerces in recent versions I believe) and then the attributes of each node can be thrown off to their respective original methods to recreate the graphics on the canvas.