org.sbml.jsbml.xml
public class XMLNode extends XMLToken
Beginning with version 1.0, JSBML implements an XML abstraction layer, like
LibSBML. The basic data object in the XML abstraction is a node,
represented by XMLNode
.
An XMLNode
can contain any number of children. Each child is another
XMLNode
, thereby forming a tree. The methods
getChildCount()
and getChildAt(int)
can be
used to access the tree structure starting from a given node.
Each XMLNode
is subclassed from XMLToken
, and thus has the
same methods available as XMLToken
. These methods include
XMLToken.getNamespaces()
, XMLToken.getPrefix()
,
XMLToken.getName()
, XMLToken.getURI()
, and
XMLToken.getAttributes()
.
String
and an XMLNode
JSBML provides the following utility functions for converting an XML
String
(e.g., <annotation>...</annotation>) to/from an
XMLNode
object.
toXMLString()
returns a String
representation of
the XMLNode
object.convertXMLNodeToString(XMLNode)
(static function) returns a
String
representation of the given XMLNode
object.convertStringToXMLNode(String)
(static function) returns an
XMLNode
object converted from the given XML String
.
The returned XMLNode
object by
convertStringToXMLNode(String)
is a dummy root (container)
XMLNode
if the given XML String
has two or more top-level
elements (e.g., '<p>...</p><p>...</p>'). In the dummy
root node, each top-level element in the given XML String
is
contained as a child XMLNode
. XMLToken.isEOF()
can be used to
identify if the returned XMLNode
object is a dummy node or not. Here
is an example:
// Checks if the returnedXMLNode
object by XMLNode.convertStringToXMLNode() is a dummy root node: String str = '...';XMLNode
xn =XMLNode
.convertStringToXMLNode(str); if (xn == null) { // returned value is null (error) ... } else if ( xn.isEOF() ) { // root node is a dummy node for (int i=0; i < xn.getChildCount(); i++) { // access to each child node of the dummy node.XMLNode
xnChild = xn.getChild(i); ... } } else { // root node is NOT a dummy node ... }
Modifier and Type | Field and Description |
---|---|
private java.util.List<XMLNode> |
childrenElements |
private static SBMLReader |
notesReader
This reader is used to parse all notes-Strings.
|
private static long |
serialVersionUID
Generated serial version identifier
|
attributes, characters, column, isEndElement, isEOF, isStartElement, isText, line, namespaces, triple
listOfListeners, parent, UNKNOWN_ATTRIBUTES, UNKNOWN_ELEMENTS
Constructor and Description |
---|
XMLNode()
Creates a new empty
XMLNode with no children. |
XMLNode(java.lang.String chars)
Creates a text
XMLNode . |
XMLNode(java.lang.String chars,
long line)
Creates a text
XMLNode . |
XMLNode(java.lang.String chars,
long line,
long column)
Creates a text
XMLNode . |
XMLNode(XMLNode orig)
Creates a copy of this
XMLNode . |
XMLNode(XMLToken orig)
Creates a new
XMLNode by copying token. |
XMLNode(XMLTriple triple)
Creates an end element
XMLNode . |
XMLNode(XMLTriple triple,
long line)
Creates an end element
XMLNode . |
XMLNode(XMLTriple triple,
long line,
long column)
Creates an end element
XMLNode . |
XMLNode(XMLTriple triple,
XMLAttributes attributes)
Creates a start element
XMLNode with the given set of attributes. |
XMLNode(XMLTriple triple,
XMLAttributes attributes,
long line)
Creates a start element
XMLNode with the given set of attributes. |
XMLNode(XMLTriple triple,
XMLAttributes attributes,
long line,
long column)
Creates a start element
XMLNode with the given set of attributes. |
XMLNode(XMLTriple triple,
XMLAttributes attributes,
XMLNamespaces namespaces)
Creates a new start element
XMLNode with the given set of attributes and
namespace declarations. |
XMLNode(XMLTriple triple,
XMLAttributes attributes,
XMLNamespaces namespaces,
long line)
Creates a new start element
XMLNode with the given set of attributes and
namespace declarations. |
XMLNode(XMLTriple triple,
XMLAttributes attributes,
XMLNamespaces namespaces,
long line,
long column)
Creates a new start element
XMLNode with the given set of attributes and
namespace declarations. |
Modifier and Type | Method and Description |
---|---|
int |
addChild(XMLNode node)
Adds a child to this
XMLNode . |
XMLNode |
clone() |
static XMLNode |
convertStringToXMLNode(java.lang.String xmlstr)
Returns an
XMLNode which is derived from a String
containing XML content. |
static XMLNode |
convertStringToXMLNode(java.lang.String xmlstr,
XMLNamespaces xmlns)
Returns an
XMLNode which is derived from a string containing XML
content. |
static java.lang.String |
convertXMLNodeToString(XMLNode node)
Returns a string representation of a given
XMLNode . |
boolean |
getAllowsChildren() |
XMLNode |
getChildAt(int childIndex) |
int |
getChildCount() |
XMLNode |
insertChild(int n,
XMLNode node)
Inserts a node as the
n th child of this
XMLNode . |
XMLNode |
removeChild(int n)
Removes the
n th child of this XMLNode and returns the
removed node. |
boolean |
removeChild(XMLNode xmlNode) |
int |
removeChildren()
Removes all children from this node.
|
java.lang.String |
toString() |
java.lang.String |
toXMLString()
Returns a string representation of this
XMLNode . |
addAttr, addAttr, addAttr, addAttr, addNamespace, addNamespace, append, clearAttributes, clearNamespaces, equals, getAttributes, getAttributesLength, getAttrIndex, getAttrIndex, getAttrIndex, getAttrName, getAttrPrefix, getAttrPrefixedName, getAttrURI, getAttrValue, getAttrValue, getAttrValue, getAttrValue, getCharacters, getColumn, getLine, getName, getNamespaceIndex, getNamespaceIndexByPrefix, getNamespacePrefix, getNamespacePrefix, getNamespaces, getNamespacesLength, getNamespaceURI, getNamespaceURI, getNamespaceURI, getPrefix, getURI, hasAttr, hasAttr, hasAttr, hasAttr, hashCode, hasNamespaceNS, hasNamespacePrefix, hasNamespaceURI, isAttributesEmpty, isElement, isEnd, isEndFor, isEOF, isNamespacesEmpty, isStart, isText, removeAttr, removeAttr, removeAttr, removeAttr, removeNamespace, removeNamespace, setAttributes, setCharacters, setEnd, setEOF, setNamespaces, setTriple, unsetEnd
addAllChangeListeners, addTreeNodeChangeListener, addTreeNodeChangeListener, children, clearUserObjects, containsUserObjectKey, filter, filter, filter, fireNodeAddedEvent, fireNodeRemovedEvent, firePropertyChange, getIndex, getListOfTreeNodeChangeListeners, getNumChildren, getParent, getRoot, getTreeNodeChangeListenerCount, getUserObject, indexOf, isLeaf, isRoot, isSetParent, isSetUserObjects, notifyChildChange, putUserObject, removeAllTreeNodeChangeListeners, removeFromParent, removeTreeNodeChangeListener, removeTreeNodeChangeListener, removeUserObject, setParent, userObjectKeySet
private static final long serialVersionUID
private static SBMLReader notesReader
SBMLReader
every time notes are being set or appended, thus, this instance
is static and should be used to parse all notes.private java.util.List<XMLNode> childrenElements
public XMLNode()
XMLNode
with no children.public XMLNode(java.lang.String chars)
XMLNode
.
chars
- a string, the text to be added to the XMLToken
public XMLNode(java.lang.String chars, long line)
XMLNode
.
chars
- a string, the text to be added to the XMLToken
line
- a long integer, the line number (default = 0).public XMLNode(java.lang.String chars, long line, long column)
XMLNode
.
chars
- a string, the text to be added to the XMLToken
line
- a long integer, the line number (default = 0).column
- a long integer, the column number (default = 0).public XMLNode(XMLNode orig)
XMLNode
.
orig
- the XMLNode
instance to copy.public XMLNode(XMLTriple triple)
XMLNode
.
triple
- XMLTriple
.public XMLNode(XMLTriple triple, long line)
XMLNode
.
triple
- XMLTriple
.line
- a long integer, the line number (default = 0).public XMLNode(XMLTriple triple, long line, long column)
XMLNode
.
triple
- XMLTriple
.line
- a long integer, the line number (default = 0).column
- a long integer, the column number (default = 0).public XMLNode(XMLTriple triple, XMLAttributes attributes)
XMLNode
with the given set of attributes.
triple
- XMLTriple
.attributes
- XMLAttributes
, the attributes to set.public XMLNode(XMLTriple triple, XMLAttributes attributes, long line)
XMLNode
with the given set of attributes.
triple
- XMLTriple
.attributes
- XMLAttributes
, the attributes to set.line
- a long integer, the line number (default = 0).public XMLNode(XMLTriple triple, XMLAttributes attributes, long line, long column)
XMLNode
with the given set of attributes.
triple
- XMLTriple
.attributes
- XMLAttributes
, the attributes to set.line
- a long integer, the line number (default = 0).column
- a long integer, the column number (default = 0).public XMLNode(XMLTriple triple, XMLAttributes attributes, XMLNamespaces namespaces)
XMLNode
with the given set of attributes and
namespace declarations.
triple
- XMLTriple
.attributes
- XMLAttributes
, the attributes to set.namespaces
- XMLNamespaces
, the namespaces to set.public XMLNode(XMLTriple triple, XMLAttributes attributes, XMLNamespaces namespaces, long line)
XMLNode
with the given set of attributes and
namespace declarations.
triple
- XMLTriple
.attributes
- XMLAttributes
, the attributes to set.namespaces
- XMLNamespaces
, the namespaces to set.line
- a long integer, the line number (default = 0).public XMLNode(XMLTriple triple, XMLAttributes attributes, XMLNamespaces namespaces, long line, long column)
XMLNode
with the given set of attributes and
namespace declarations.
triple
- XMLTriple
.attributes
- XMLAttributes
, the attributes to set.namespaces
- XMLNamespaces
, the namespaces to set.line
- a long integer, the line number (default = 0).column
- a long integer, the column number (default = 0).public static XMLNode convertStringToXMLNode(java.lang.String xmlstr) throws javax.xml.stream.XMLStreamException
XMLNode
which is derived from a String
containing XML content.
The XML namespace must be defined using argument xmlns
if the
corresponding XML namespace attribute is not part of the String
of
the first argument.
xmlstr
- String
to be converted to a XML node.xmlns
- XMLNamespaces
the namespaces to set (default value is
null
).XMLNode
which is converted from string xmlstr
.
null
is returned if the conversion failed.javax.xml.stream.XMLStreamException
public static XMLNode convertStringToXMLNode(java.lang.String xmlstr, XMLNamespaces xmlns)
XMLNode
which is derived from a string containing XML
content.
The XML namespace must be defined using argument xmlns
if the
corresponding XML namespace attribute is not part of the string of the
first argument.
xmlstr
- string to be converted to a XML node.xmlns
- XMLNamespaces
the namespaces to set (default value is null
). This argument is ignored at the moment.
XMLNode
which is converted from string xmlstr
. null
is returned
if the conversion failed.public static java.lang.String convertXMLNodeToString(XMLNode node) throws javax.xml.stream.XMLStreamException
XMLNode
.
node
- the XMLNode
to be represented as a string
node
javax.xml.stream.XMLStreamException
public int addChild(XMLNode node)
XMLNode
.
The given node
is added at the end of the list of children.
node
- the XMLNode
to be added as child.
public boolean getAllowsChildren()
public XMLNode getChildAt(int childIndex)
public int getChildCount()
public XMLNode insertChild(int n, XMLNode node)
n
th child of this
XMLNode
.
If the given index n
is out of range for this XMLNode
instance,
the node
is added at the end of the list of children. Even in
that situation, this method does not throw an error.
n
- an integer, the index at which the given node is insertednode
- an XMLNode
to be inserted as n
th child.
node
public XMLNode removeChild(int n)
n
th child of this XMLNode
and returns the
removed node.
It is important to keep in mind that a given XMLNode
may have more
than one child. Calling this method erases all existing references to
child nodes after the given position n
. If the index n
is
greater than the number of child nodes in this XMLNode
, this method
takes no action (and returns null
).
n
- an integer, the index of the node to be removed
null
if n
is greater than the number
of children in this node
public int removeChildren()
public java.lang.String toXMLString() throws javax.xml.stream.XMLStreamException
XMLNode
.
XMLNode
.javax.xml.stream.XMLStreamException
public boolean removeChild(XMLNode xmlNode)
xmlNode
-