APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.utils

public Class XmlReader

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .InputStreamReader, .Reader, com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.utils.ObjectMap.Entry

Lightweight XML parser. Supports a subset of XML features: elements, attributes, text, predefined entities, CDATA, mixed content. Namespaces are parsed as part of the element or attribute name. Prologs and doctypes are ignored. Only 8-bit character encodings are supported. Input is assumed to be well formed.

The default behavior is to parse the XML into a DOM. Extends this class and override methods to perform event driven parsing. When this is done, the parse methods will return null.
Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static final byte[]
private static final short[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final char[]
private static final byte[]
private XmlReader.Element
private final Array<XmlReader.Element>
private String
private XmlReader.Element
private final StringBuilder
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
attribute(String name, String value)

protected void
protected String
entity(String name)

private static byte[]
private static short[]
private static byte[]
private static byte[]
private static byte[]
private static byte[]
private static byte[]
private static char[]
private static byte[]
protected void
open(String name)

public XmlReader.Element
public XmlReader.Element
parse(Reader reader)

public XmlReader.Element
public XmlReader.Element
public XmlReader.Element
parse(char[] data, int offset, int length)

protected void
text(String text)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_xml_actionsback to summary
private static final byte[] _xml_actions
_xml_index_offsetsback to summary
private static final short[] _xml_index_offsets
_xml_indiciesback to summary
private static final byte[] _xml_indicies
_xml_key_offsetsback to summary
private static final byte[] _xml_key_offsets
_xml_range_lengthsback to summary
private static final byte[] _xml_range_lengths
_xml_single_lengthsback to summary
private static final byte[] _xml_single_lengths
_xml_trans_actionsback to summary
private static final byte[] _xml_trans_actions
_xml_trans_keysback to summary
private static final char[] _xml_trans_keys
_xml_trans_targsback to summary
private static final byte[] _xml_trans_targs
currentback to summary
private XmlReader.Element current
elementsback to summary
private final Array<XmlReader.Element> elements
entitiesTextback to summary
private String entitiesText
rootback to summary
private XmlReader.Element root
textBufferback to summary
private final StringBuilder textBuffer
xml_en_elementBodyback to summary
pack-priv static final int xml_en_elementBody
xml_en_mainback to summary
pack-priv static final int xml_en_main
xml_errorback to summary
pack-priv static final int xml_error
xml_first_finalback to summary
pack-priv static final int xml_first_final
xml_startback to summary
pack-priv static final int xml_start

Constructor Detail

XmlReaderback to summary
public XmlReader()

Method Detail

attributeback to summary
protected void attribute(String name, String value)
closeback to summary
protected void close()
entityback to summary
protected String entity(String name)
Annotations
@Null
init__xml_actions_0back to summary
private static byte[] init__xml_actions_0()
init__xml_index_offsets_0back to summary
private static short[] init__xml_index_offsets_0()
init__xml_indicies_0back to summary
private static byte[] init__xml_indicies_0()
init__xml_key_offsets_0back to summary
private static byte[] init__xml_key_offsets_0()
init__xml_range_lengths_0back to summary
private static byte[] init__xml_range_lengths_0()
init__xml_single_lengths_0back to summary
private static byte[] init__xml_single_lengths_0()
init__xml_trans_actions_0back to summary
private static byte[] init__xml_trans_actions_0()
init__xml_trans_keys_0back to summary
private static char[] init__xml_trans_keys_0()
init__xml_trans_targs_0back to summary
private static byte[] init__xml_trans_targs_0()
openback to summary
protected void open(String name)
parseback to summary
public XmlReader.Element parse(String xml)
parseback to summary
public XmlReader.Element parse(Reader reader)
parseback to summary
public XmlReader.Element parse(InputStream input)
parseback to summary
public XmlReader.Element parse(FileHandle file)
parseback to summary
public XmlReader.Element parse(char[] data, int offset, int length)
textback to summary
protected void text(String text)
com.badlogic.gdx.utils back to summary

public Class XmlReader.Element

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private ObjectMap<String, String>
private Array<XmlReader.Element>
private final String
private XmlReader.Element
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public String
get(String name)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

public String
get(String name, String defaultValue)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

public String
public String
getAttribute(String name, String defaultValue)

public ObjectMap<String, String>
public boolean
getBoolean(String name)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

public boolean
getBoolean(String name, boolean defaultValue)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

public boolean
public boolean
getBooleanAttribute(String name, boolean defaultValue)

public XmlReader.Element
getChild(int index)

public XmlReader.Element
getChildByName(String
the name of the child Element
name
)

Returns: the first child having the given name or null, does not recurse

public XmlReader.Element
getChildByNameRecursive(String
the name of the child Element
name
)

Returns: the first child having the given name or null, recurses

public int
public Array<XmlReader.Element>
public Array<XmlReader.Element>
getChildrenByName(String
the name of the children
name
)

Returns: the children with the given name or an empty Array

public Array<XmlReader.Element>
getChildrenByNameRecursively(String
the name of the children
name
)

Returns: the children with the given name or an empty Array

private void
public float
getFloat(String name)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

public float
getFloat(String name, float defaultValue)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

public float
public float
getFloatAttribute(String name, float defaultValue)

public int
getInt(String name)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

public int
getInt(String name, int defaultValue)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

public int
public int
getIntAttribute(String name, int defaultValue)

public String
public XmlReader.Element
public String
public boolean
public boolean
public boolean
public void
public void
removeChild(int index)

public void
public void
public void
setAttribute(String name, String value)

public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public String
toString(String indent)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

attributesback to summary
private ObjectMap<String, String> attributes
childrenback to summary
private Array<XmlReader.Element> children
nameback to summary
private final String name
parentback to summary
private XmlReader.Element parent
textback to summary
private String text

Constructor Detail

Elementback to summary
public Element(String name, XmlReader.Element parent)

Method Detail

addChildback to summary
public void addChild(XmlReader.Element element)
getback to summary
public String get(String name)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

Exceptions
GdxRuntimeException:
if no attribute or child was not found.
getback to summary
public String get(String name, String defaultValue)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

Exceptions
GdxRuntimeException:
if no attribute or child was not found.
getAttributeback to summary
public String getAttribute(String name)
Exceptions
GdxRuntimeException:
if the attribute was not found.
getAttributeback to summary
public String getAttribute(String name, String defaultValue)
getAttributesback to summary
public ObjectMap<String, String> getAttributes()
getBooleanback to summary
public boolean getBoolean(String name)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

Exceptions
GdxRuntimeException:
if no attribute or child was not found.
getBooleanback to summary
public boolean getBoolean(String name, boolean defaultValue)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

Exceptions
GdxRuntimeException:
if no attribute or child was not found.
getBooleanAttributeback to summary
public boolean getBooleanAttribute(String name)
Exceptions
GdxRuntimeException:
if the attribute was not found.
getBooleanAttributeback to summary
public boolean getBooleanAttribute(String name, boolean defaultValue)
getChildback to summary
public XmlReader.Element getChild(int index)
Exceptions
GdxRuntimeException:
if the element has no children.
getChildByNameback to summary
public XmlReader.Element getChildByName(String name)
Parameters
name:String

the name of the child Element

Returns:XmlReader.Element

the first child having the given name or null, does not recurse

Annotations
@Null
getChildByNameRecursiveback to summary
public XmlReader.Element getChildByNameRecursive(String name)
Parameters
name:String

the name of the child Element

Returns:XmlReader.Element

the first child having the given name or null, recurses

Annotations
@Null
getChildCountback to summary
public int getChildCount()
getChildrenback to summary
public Array<XmlReader.Element> getChildren()
getChildrenByNameback to summary
public Array<XmlReader.Element> getChildrenByName(String name)
Parameters
name:String

the name of the children

Returns:Array<XmlReader.Element>

the children with the given name or an empty Array

getChildrenByNameRecursivelyback to summary
public Array<XmlReader.Element> getChildrenByNameRecursively(String name)
Parameters
name:String

the name of the children

Returns:Array<XmlReader.Element>

the children with the given name or an empty Array

getChildrenByNameRecursivelyback to summary
private void getChildrenByNameRecursively(String name, Array<XmlReader.Element> result)
getFloatback to summary
public float getFloat(String name)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

Exceptions
GdxRuntimeException:
if no attribute or child was not found.
getFloatback to summary
public float getFloat(String name, float defaultValue)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

Exceptions
GdxRuntimeException:
if no attribute or child was not found.
getFloatAttributeback to summary
public float getFloatAttribute(String name)
Exceptions
GdxRuntimeException:
if the attribute was not found.
getFloatAttributeback to summary
public float getFloatAttribute(String name, float defaultValue)
getIntback to summary
public int getInt(String name)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

Exceptions
GdxRuntimeException:
if no attribute or child was not found.
getIntback to summary
public int getInt(String name, int defaultValue)

Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.

Exceptions
GdxRuntimeException:
if no attribute or child was not found.
getIntAttributeback to summary
public int getIntAttribute(String name)
Exceptions
GdxRuntimeException:
if the attribute was not found.
getIntAttributeback to summary
public int getIntAttribute(String name, int defaultValue)
getNameback to summary
public String getName()
getParentback to summary
public XmlReader.Element getParent()
getTextback to summary
public String getText()
hasAttributeback to summary
public boolean hasAttribute(String name)
hasChildback to summary
public boolean hasChild(String name)
hasChildRecursiveback to summary
public boolean hasChildRecursive(String name)
removeback to summary
public void remove()
removeChildback to summary
public void removeChild(int index)
removeChildback to summary
public void removeChild(XmlReader.Element child)
replaceChildback to summary
public void replaceChild(XmlReader.Element child, XmlReader.Element replacement)
setAttributeback to summary
public void setAttribute(String name, String value)
setTextback to summary
public void setText(String text)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

toStringback to summary
public String toString(String indent)