SweetXML User Guide

Table of Contents

Syntax

Tags

Tags appear simply as a tag name — no delimiters, no nothing.

This SweetXML......is equivalent to this XML.
tag another-tag <tag/> <another-tag/>

Indentation determines nesting.

rivers mississippi poudre north-fork lakes superior calhoun <rivers> <mississippi/> <poudre> <north-fork/> </poudre> </rivers> <lakes> <superior/> <calhoun/> </lakes>

SweetXML requires consistent indentation. Be careful of tabs! If different lines are indented with different mixtures of tabs and spaces, SweetXML will give a parse error. If your text editor allows it, it is best to avoid confusion by using soft tabs (i.e. no actual tab characters, only spaces).

Each tag appear on a line by itself. There is currently no syntax that allows multiple tags on the same line. Exploration of this feature is in the roadmap.

Attributes

Attributes follow a tag on the same line, in the form name="value" (either double or single quotes work):

pet type="budgie" name="Pegasus" pet type='dog' name='Goulash' <pet type="budgie" name="Pegasus"/> <pet type="dog" name="Goulash"/>

If the attribute value contains only letters, numbers, dashes, periods, and underscores, then the quotes are optional:

pet type=cat name=Luke status=very_clumsy pet type=cat name="Mr. Man" <pet type="cat" name="Luke" status="very_clumsy"/> <pet type="cat" name="Mr. Man"/>

Note that the attribute value "Mr. Man" requires quotes because it contains a space.

You can split a tag across multiple lines with a vertical bar:

pet | type="cat" | name="Luke" | color="black" | size="large" | likable="very" | clumsy="very" <pet type="cat" name="Luke" color="black" size="large" likable="very" clumsy="very" />

Note that the attribute value "Mr. Man" requires quotes because it contains a space.

Text

Text appears in quotes on a line by itself.

name "Pogo Possum" <name>Pogo Possum</name>

Quoted text can span multiple lines. White space (including line breaks) is preserved if and only if it is inside quotes.

name "Pogo" "Possum" description "Inhabitant of Okefenokee Swamp, and star of the comic strip of the same name." <name>PogoPossum</name> <description>Inhabitant of Okefenokee Swamp, and star of the comic strip of the same name.</description>

Quotes inside quoted text can be escaped using the usual XML entities. (Entities have exactly the same syntax in SweetXML.)

name: "Hayao &quot;Ghibli&quot; Miyazaki" remark: 'We&apos;re making a mystery here, so make it mysterious.' <name>Hayao "Ghibli" Miyazaki</name> <remark>We're making a mystery here, so make it mysterious.</remark>

Note that you can often avoid the need for escaping by using single instead of double quotes or vice versa.

name: 'Hayao "Ghibli" Miyazaki' remark: "We're making a mystery here, so make it mysterious." <name>Hayao "Ghibli" Miyazaki</name> <remark>We're making a mystery here, so make it mysterious.</remark>

Text nested inside a tag may appear on the same line as the tag when preceded by a colon.

name: "Pogo Possum" <name>Pogo Possum</name>

When text appears after a colon, the quotes are optional if the text contains only letters, numbers, dashes, periods, and underscores.

name: "Pogo Possum" species: opossum <name>Pogo Possum</name> <species>opossum</species>

Note that quotes are optional only when the text follow a colon. If text appears on a line by itself, quotes are always required. Without quotes, SweetXML will see a tag, not text.

marco "polo" marco polo <marco>polo</marco> <marco> <polo/> </marco>

Other Basics

A # character makes the remainder of the line a comment.

# here follows a name name : "Harold J. Smooter" # not a real name <!--here follows a name--> <name>Harold J. Smooter <!--not a real name--> </name>

Entities have exactly the same syntax as in XML.

&foo; &foo;

Because the colon is already used for inline text, namespaces use a slash:

document | xmlns/xsi="..." | xsi/schemaLocation="..." <document xmlns:xsi="..." xsi:schemaLocation="...">

Document Preamble

SweetXML documents have no place to specify a version number or encoding. Consideration of this feature is in the roadmap.

SweetXML is not particularly concerned with features of XML other than the document body itself. It does not address validation and transformation in any special way.

You can specify a DOCTYPE at the beginning of your document, using exactly the same syntax as XML. Line breaks and indentation in the DOCTYPE are not significant.

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> hibernate-configuration session-factory ... <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> ...

This is the complete syntax of SweetXML.

Check out the examples to see how it all fits together.

Table of Contents
innig