Open Source Cross-Platform Game Programming

Xml

Library for parsing XML. The underlying implementation is a common implementation that is translated to the various target platforms, so parsing is consistent between platforms and not prone to library-specific quirks.

enum NodeType[link]

Enum for identifying the type of a parse node

NameDescription
ELEMENT

TEXT

COMMENT

enum XmlOption[link]

A bit mask of various options used by the parser.

NameDescription
TRIM_WHITESPACE

Trims the whitespace off text elements.

FAIL_SILENTLY

If there is a syntax error, return null instead of throwing an exception

NAMESPACES

Return an XML-namespace aware parse node tree instead of a strict literal parse tree.

function parse(xmlString, options)[link]

Parses a string and returns an XML node tree. Capable of parsing the tree by the basic XML standard without namespaces, or with. See Xml.XmlOption.

Arguments

NameTypeOptionalDescription
xmlString string

Some XML

options Xml.XmlOption Optional

A bitmask of extra options for the parser.

class XmlElement[link]

Represents an XML Element

Fields

NameTypeDescription
.name string

The name of the element.

.attributes dictionary

A dictionary with string keys for all the element's attributes

.children List of object

A list of XmlElements, XmlText, or XmlComments that are nested within this element, in the order they appear. Use the .type field to distinguish them.

.type Xml.NodeType

Always set to Xml.NodeType.ELEMENT

class XmlNamespacedAttribute[link]

Represents an attribute in an XML element with namespace information. This is only used if the XML is parsed with the NAMESPACES flag. Otherwise the element contains a simple string-to-string dictionary.

Fields

NameTypeDescription
.name string

The name of this attribute without the namespace alias prefix.

.alias string

The namespace alias prefix, if present.

.xmlns string

The namespace of this element, if present.

.value string

The value of the attribute.

class XmlNamespacedElement[link]

Represents an XML Element along with resolved namespace information

Fields

NameTypeDescription
.name string

The name of this element without the namespace alias prefix.

.alias string

The namespace alias prefix, if present.

.xmlns string

The namespace of this element, if present.

.attributes List of Xml.XmlNamespacedAttribute

A list of attributes in this element. Because namespaces can allow for multiple attributes with the same root name and aliases can be arbitrary, this value is given as a list of attribute objects, instead of a dictionary keyed by the attribute name.

.children List of object

A list of XmlNamespacedElements, XmlText, or XmlComments that are nested within this element, in the order they appear. Use the .type field to distinguish them.

.type Xml.NodeType

Always set to Xml.NodeType.ELEMENT

class XmlText[link]

Represents a blob of text present in an XML file, either as the body of an element or text between elements.

Fields

NameTypeDescription
.value string

The value of the text.

.type Xml.NodeType

Always set to Xml.NodeType.TEXT