libSBML C++ API  5.20.2
XMLToken Class Reference
Inheritance diagram for XMLToken:
[legend]

Detailed Description

A token in an XML stream.

This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. This class is not prescribed by the SBML specifications, although it is used to implement features defined in SBML.

The libSBML XML parser interface can read an XML file or data stream and convert the contents into tokens. The tokens represent items in the XML stream, either XML elements (start or end tags) or text that appears as content inside an element. The XMLToken class is libSBML's low-level representation of these entities.

Each XMLToken has the following information associated with it:

  1. Qualified name: every XML element or XML attribute has a name (e.g., for the element <mytag>, the name is "mytag"), but this name may be qualified with a namespace (e.g., it may appear as <someNamespace:mytag> in the input). An XMLToken stores the name of a token, along with any namespace qualification present, through the use of an XMLTriple object. This object stores the bare name of the element, its XML namespace prefix (if any), and the XML namespace with which that prefix is associated.
  2. Namespaces: An XML token can have one or more XML namespaces associated with it. These namespaces may be specified explicitly on the element or inherited from parent elements. In libSBML, a list of namespaces is stored in an XMLNamespaces object. An XMLToken possesses a field for storing an XMLNamespaces object.
  3. Attributes: XML elements can have attributes associated with them, and these attributes can have values assigned to them. The set of attribute-value pairs is stored in an XMLAttributes object stored in an XMLToken object. (Note: only elements can have attributes—text blocks cannot have them in XML.)
  4. Line number: the line number in the input where the token appears.
  5. Column number: the column number in the input where the token appears.

The XMLToken class serves as base class for XMLNode. XML lends itself to a tree-structured representation, and in libSBML, the nodes in an XML document tree are XMLNode objects. Most higher-level libSBML classes and methods that offer XML-level functionality (such as the methods on SBase for interacting with annotations) work with XMLNode objects rather than XMLToken objects directly.

See also
XMLNode
XMLTriple
XMLAttributes
XMLNamespaces
Examples
addingEvidenceCodes_2.cpp.

Public Member Functions

int addAttr (const std::string &name, const std::string &value, const std::string namespaceURI="", const std::string prefix="")
 Adds an attribute to the XML element represented by this token. More...
 
int addAttr (const XMLTriple &triple, const std::string &value)
 Adds an attribute to the XML element represented by this token. More...
 
int addNamespace (const std::string &uri, const std::string prefix="")
 Appends an XML namespace declaration to this token. More...
 
int append (const std::string &chars)
 Appends characters to the text content of token. More...
 
int clearAttributes ()
 Removes all attributes of this XMLToken object. More...
 
int clearNamespaces ()
 Removes all XML namespace declarations from this token. More...
 
XMLTokenclone () const
 Creates and returns a deep copy of this XMLToken object. More...
 
const XMLAttributesgetAttributes () const
 Returns the attributes of the XML element represented by this token. More...
 
int getAttributesLength () const
 Returns the number of attributes on this XMLToken object. More...
 
int getAttrIndex (const std::string &name, const std::string uri="") const
 Returns the index of the attribute with the given name and namespace URI. More...
 
int getAttrIndex (const XMLTriple &triple) const
 Returns the index of the attribute defined by the given XMLTriple object. More...
 
std::string getAttrName (int index) const
 Returns the name of the nth attribute in this token's list of attributes. More...
 
std::string getAttrPrefix (int index) const
 Returns the prefix of the nth attribute in this token's list of attributes. More...
 
std::string getAttrPrefixedName (int index) const
 Returns the prefixed name of the nth attribute in this token's list of attributes. More...
 
std::string getAttrURI (int index) const
 Returns the XML namespace URI of the nth attribute in this token's list of attributes. More...
 
std::string getAttrValue (const std::string &name, const std::string uri="") const
 Returns the value of the attribute with a given name and XML namespace URI. More...
 
std::string getAttrValue (const XMLTriple &triple) const
 Returns the value of the attribute specified by a given XMLTriple object. More...
 
std::string getAttrValue (int index) const
 Returns the value of the nth attribute in this token's list of attributes. More...
 
const std::string & getCharacters () const
 Returns the character text of token. More...
 
unsigned int getColumn () const
 Returns the column number at which this token occurs in the input. More...
 
unsigned int getLine () const
 Returns the line number at which this token occurs in the input. More...
 
const std::string & getName () const
 Returns the (unqualified) name of token. More...
 
int getNamespaceIndex (const std::string &uri) const
 Returns the index of an XML namespace declaration based on its URI. More...
 
int getNamespaceIndexByPrefix (const std::string &prefix) const
 Returns the index of an XML namespace declaration based on its prefix. More...
 
std::string getNamespacePrefix (const std::string &uri) const
 Returns the prefix associated with a given XML namespace URI on this token. More...
 
std::string getNamespacePrefix (int index) const
 Returns the prefix of the nth XML namespace declaration. More...
 
const XMLNamespacesgetNamespaces () const
 Returns the XML namespaces declared for this token. More...
 
int getNamespacesLength () const
 Returns the number of XML namespaces declared on this token. More...
 
std::string getNamespaceURI (const std::string prefix="") const
 Returns the URI of an XML namespace with a given prefix. More...
 
std::string getNamespaceURI (int index) const
 Returns the URI of the nth XML namespace declared on this token. More...
 
const std::string & getPrefix () const
 Returns the XML namespace prefix of token. More...
 
const std::string & getURI () const
 Returns the XML namespace URI of token. More...
 
bool hasAttr (const std::string &name, const std::string uri="") const
 Returns true if an attribute with a given name and namespace URI exists. More...
 
bool hasAttr (const XMLTriple &triple) const
 Returns true if an attribute defined by a given XMLTriple object exists. More...
 
bool hasAttr (int index) const
 Returns true if an attribute with the given index exists. More...
 
bool hasNamespaceNS (const std::string &uri, const std::string &prefix) const
 Returns true if this token has an XML namespace with a given prefix and URI combination. More...
 
bool hasNamespacePrefix (const std::string &prefix) const
 Returns true if this token has an XML namespace with a given prefix. More...
 
bool hasNamespaceURI (const std::string &uri) const
 Returns true if this token has an XML namespace with a given URI. More...
 
bool isAttributesEmpty () const
 Returns true if this token has no attributes. More...
 
bool isElement () const
 Returns true if this token represents an XML element. More...
 
bool isEnd () const
 Returns true if this token represents an XML end element. More...
 
bool isEndFor (const XMLToken &element) const
 Returns true if this token represents an XML end element for a particular start element. More...
 
bool isEOF () const
 Returns true if this token is an end of file marker. More...
 
bool isNamespacesEmpty () const
 Returns true if there are no namespaces declared on this token. More...
 
bool isStart () const
 Returns true if this token represents an XML start element. More...
 
bool isText () const
 Returns true if this token represents an XML text element. More...
 
XMLTokenoperator= (const XMLToken &rhs)
 Assignment operator for XMLToken. More...
 
int removeAttr (const std::string &name, const std::string uri="")
 Removes an attribute from the XML element represented by this token. More...
 
int removeAttr (const XMLTriple &triple)
 Removes an attribute from the XML element represented by this token. More...
 
int removeAttr (int n)
 Removes the nth attribute from the XML element represented by this token. More...
 
int removeNamespace (const std::string &prefix)
 Removes an XML namespace declaration having a given prefix. More...
 
int removeNamespace (int index)
 Removes the nth XML namespace declaration. More...
 
int setAttributes (const XMLAttributes &attributes)
 Sets the attributes on the XML element represented by this token. More...
 
int setCharacters (const std::string &chars)
 Sets the characters for this XMLToken. More...
 
int setEnd ()
 Declares that this token represents an XML element end tag. More...
 
int setEOF ()
 Declares that this token is an end-of-file/input marker. More...
 
int setNamespaces (const XMLNamespaces &namespaces)
 Sets the XML namespaces on this XML element. More...
 
int setTriple (const XMLTriple &triple)
 Sets the name, namespace prefix and namespace URI of this token. More...
 
std::string toString ()
 Prints a string representation of the underlying token stream. More...
 
int unsetEnd ()
 Declares that this token no longer represents an XML start/end element. More...
 
 XMLToken ()
 Creates a new empty XMLToken object. More...
 
 XMLToken (const std::string &chars, const unsigned int line=0, const unsigned int column=0)
 Creates a text object. More...
 
 XMLToken (const XMLToken &orig)
 Copy constructor; creates a copy of this XMLToken object. More...
 
 XMLToken (const XMLTriple &triple, const unsigned int line=0, const unsigned int column=0)
 Creates an XML end element. More...
 
 XMLToken (const XMLTriple &triple, const XMLAttributes &attributes, const unsigned int line=0, const unsigned int column=0)
 Creates an XML start element with attributes. More...
 
 XMLToken (const XMLTriple &triple, const XMLAttributes &attributes, const XMLNamespaces &namespaces, const unsigned int line=0, const unsigned int column=0)
 Creates an XML start element with attributes and namespace declarations. More...
 
virtual ~XMLToken ()
 Destroys this XMLToken object. More...
 

Constructor & Destructor Documentation

◆ XMLToken() [1/6]

XMLToken::XMLToken ( )

Creates a new empty XMLToken object.

◆ XMLToken() [2/6]

XMLToken::XMLToken ( const XMLTriple triple,
const XMLAttributes attributes,
const XMLNamespaces namespaces,
const unsigned int  line = 0,
const unsigned int  column = 0 
)

Creates an XML start element with attributes and namespace declarations.

Parameters
triplean XMLTriple object describing the start tag.
attributesXMLAttributes, the attributes to set on the element to be created.
namespacesXMLNamespaces, the namespaces to set on the element to be created.
linean unsigned int, the line number to associate with the token (default = 0).
columnan unsigned int, the column number to associate with the token (default = 0).

◆ XMLToken() [3/6]

XMLToken::XMLToken ( const XMLTriple triple,
const XMLAttributes attributes,
const unsigned int  line = 0,
const unsigned int  column = 0 
)

Creates an XML start element with attributes.

Parameters
triplean XMLTriple object describing the start tag.
attributesXMLAttributes, the attributes to set on the element to be created.
linean unsigned int, the line number to associate with the token (default = 0).
columnan unsigned int, the column number to associate with the token (default = 0).

The XML namespace component of this XMLToken object will be left empty. See the other variants of the XMLToken constructors for versions that take namespace arguments.

◆ XMLToken() [4/6]

XMLToken::XMLToken ( const XMLTriple triple,
const unsigned int  line = 0,
const unsigned int  column = 0 
)

Creates an XML end element.

Parameters
triplean XMLTriple object describing the end tag.
linean unsigned int, the line number to associate with the token (default = 0).
columnan unsigned int, the column number to associate with the token (default = 0).

◆ XMLToken() [5/6]

XMLToken::XMLToken ( const std::string &  chars,
const unsigned int  line = 0,
const unsigned int  column = 0 
)

Creates a text object.

Parameters
charsa string, the text to be added to the XMLToken object.
linean unsigned int, the line number to associate with the token (default = 0).
columnan unsigned int, the column number to associate with the token (default = 0).

◆ ~XMLToken()

XMLToken::~XMLToken ( )
virtual

Destroys this XMLToken object.

◆ XMLToken() [6/6]

XMLToken::XMLToken ( const XMLToken orig)

Copy constructor; creates a copy of this XMLToken object.

Parameters
origthe XMLToken object to copy.

Member Function Documentation

◆ addAttr() [1/2]

int XMLToken::addAttr ( const std::string &  name,
const std::string &  value,
const std::string  namespaceURI = "",
const std::string  prefix = "" 
)

Adds an attribute to the XML element represented by this token.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
namea string, the so-called "local part" of the attribute name; that is, the attribute name without any namespace qualifier or prefix.
valuea string, the value assigned to the attribute.
namespaceURIa string, the XML namespace URI of the attribute.
prefixa string, the prefix for the XML namespace.

Recall that in XML, the complete form of an attribute on an XML element is the following:

prefix:name="value"

The name part is the name of the attribute, the "value" part is the value assigned to the attribute (and it is always a quoted string), and the prefix part is an optional XML namespace prefix. Internally in libSBML, this data is stored in an XMLAttributes object associated with this XMLToken.

Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
Note
If an attribute with the same name and XML namespace URI already exists on this XMLToken object, then the previous value will be replaced with the new value provided to this method.

◆ addAttr() [2/2]

int XMLToken::addAttr ( const XMLTriple triple,
const std::string &  value 
)

Adds an attribute to the XML element represented by this token.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
triplean XMLTriple object defining the attribute, its value, and optionally its XML namespace (if any is provided).
valuea string, the value assigned to the attribute.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
Note
If an attribute with the same name and XML namespace URI already exists on this XMLToken object, then the previous value will be replaced with the new value provided to this method.

◆ addNamespace()

int XMLToken::addNamespace ( const std::string &  uri,
const std::string  prefix = "" 
)

Appends an XML namespace declaration to this token.

The namespace added will be defined by the given XML namespace URI and an optional prefix. If this XMLToken object already possesses an XML namespace declaration with the given prefix, then the existing XML namespace URI will be overwritten by the new one given by uri.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
uria string, the XML namespace URI for the namespace.
prefixa string, the namespace prefix to use.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:

◆ append()

int XMLToken::append ( const std::string &  chars)

Appends characters to the text content of token.

This method only makes sense for XMLToken objects that contains text. If this method is called on a token that represents an XML start or end tag, it will return the code LIBSBML_OPERATION_FAILED.

Parameters
charsstring, characters to append to the text of this token.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
See also
isText()
isElement()

◆ clearAttributes()

int XMLToken::clearAttributes ( )

Removes all attributes of this XMLToken object.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:

◆ clearNamespaces()

int XMLToken::clearNamespaces ( )

Removes all XML namespace declarations from this token.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:

◆ clone()

XMLToken * XMLToken::clone ( ) const

Creates and returns a deep copy of this XMLToken object.

Returns
the (deep) copy of this XMLToken object.

◆ getAttributes()

const XMLAttributes & XMLToken::getAttributes ( ) const

Returns the attributes of the XML element represented by this token.

Returns
the attributes of this XML element, stored in an XMLAttributes object.

◆ getAttributesLength()

int XMLToken::getAttributesLength ( ) const

Returns the number of attributes on this XMLToken object.

Returns
the number of attributes possessed by this token.
See also
hasAttr()

◆ getAttrIndex() [1/2]

int XMLToken::getAttrIndex ( const std::string &  name,
const std::string  uri = "" 
) const

Returns the index of the attribute with the given name and namespace URI.

Parameters
namea string, the name of the attribute.
uria string, the namespace URI of the attribute.
Returns
the index of an attribute with the given local name and namespace URI, or -1 if it is not present on this token.

◆ getAttrIndex() [2/2]

int XMLToken::getAttrIndex ( const XMLTriple triple) const

Returns the index of the attribute defined by the given XMLTriple object.

Parameters
triplethe XMLTriple object that defines the attribute whose index is being sought.
Returns
the index of an attribute with the given XMLTriple object, or -1 if no such attribute is present on this token.

◆ getAttrName()

std::string XMLToken::getAttrName ( int  index) const

Returns the name of the nth attribute in this token's list of attributes.

Parameters
indexan integer, the position of the attribute whose name is being sought.
Returns
the name of the attribute located at position n in the list of attributes possessed by this XMLToken object.
Note
If index is out of range, this method will return an empty string. XMLToken::hasAttr() can be used to test for an attribute's existence explicitly, and XMLToken::getAttributesLength() can be used to find out the number of attributes possessed by this token.
See also
hasAttr()
getAttributesLength()

◆ getAttrPrefix()

std::string XMLToken::getAttrPrefix ( int  index) const

Returns the prefix of the nth attribute in this token's list of attributes.

Parameters
indexan integer, the position of the attribute whose prefix is being sought.
Returns
the XML namespace prefix of the attribute located at position n in the list of attributes possessed by this XMLToken object.
Note
If index is out of range, this method will return an empty string. XMLToken::hasAttr() can be used to test for an attribute's existence explicitly, and XMLToken::getAttributesLength() can be used to find out the number of attributes possessed by this token.
See also
hasAttr()
getAttributesLength()

◆ getAttrPrefixedName()

std::string XMLToken::getAttrPrefixedName ( int  index) const

Returns the prefixed name of the nth attribute in this token's list of attributes.

In this context, prefixed name means the name of the attribute prefixed with the XML namespace prefix assigned to the attribute. This will be a string of the form prefix:name.

Parameters
indexan integer, the position of the attribute whose prefixed name is being sought.
Returns
the prefixed name of the attribute located at position n in the list of attributes possessed by this XMLToken object.
Note
If index is out of range, this method will return an empty string. XMLToken::hasAttr() can be used to test for an attribute's existence explicitly, and XMLToken::getAttributesLength() can be used to find out the number of attributes possessed by this token.

◆ getAttrURI()

std::string XMLToken::getAttrURI ( int  index) const

Returns the XML namespace URI of the nth attribute in this token's list of attributes.

Parameters
indexan integer, the position of the attribute whose namespace URI is being sought.
Returns
the XML namespace URI of the attribute located at position n in the list of attributes possessed by this XMLToken object.
Note
If index is out of range, this method will return an empty string. XMLToken::hasAttr() can be used to test for an attribute's existence explicitly, and XMLToken::getAttributesLength() can be used to find out the number of attributes possessed by this token.

◆ getAttrValue() [1/3]

std::string XMLToken::getAttrValue ( const std::string &  name,
const std::string  uri = "" 
) const

Returns the value of the attribute with a given name and XML namespace URI.

Parameters
namea string, the name of the attribute whose value is being sought.
uria string, the XML namespace URI of the attribute.
Returns
The value of the attribute, as a string.
Note
If an attribute with the given name and uri does not exist on this token object, this method will return an empty string. XMLToken::hasAttr() can be used to test explicitly for the presence of an attribute with a given name and namespace.

◆ getAttrValue() [2/3]

std::string XMLToken::getAttrValue ( const XMLTriple triple) const

Returns the value of the attribute specified by a given XMLTriple object.

Parameters
triplean XMLTriple describing the attribute whose value is being sought.
Returns
The value of the attribute, as a string.
Note
If an attribute defined by the given triple does not exist on this token object, this method will return an empty string. XMLToken::hasAttr() can be used to test explicitly for the existence of an attribute with the properties of a given triple.

◆ getAttrValue() [3/3]

std::string XMLToken::getAttrValue ( int  index) const

Returns the value of the nth attribute in this token's list of attributes.

Parameters
indexan integer, the position of the attribute whose value is required.
Returns
the value of the attribute located at position n in the list of attributes possessed by this XMLToken object.
Note
If index is out of range, this method will return an empty string. XMLToken::hasAttr() can be used to test for an attribute's existence explicitly, and XMLToken::getAttributesLength() can be used to find out the number of attributes possessed by this token.

◆ getCharacters()

const string & XMLToken::getCharacters ( ) const

Returns the character text of token.

Returns
the characters of this XML token. If this token is not a text token (i.e., it's an XML element and not character content), then this will return an empty string.
See also
isText()
isElement()

◆ getColumn()

unsigned int XMLToken::getColumn ( ) const

Returns the column number at which this token occurs in the input.

Returns
the column at which this XMLToken occurred.

◆ getLine()

unsigned int XMLToken::getLine ( ) const

Returns the line number at which this token occurs in the input.

Returns
the line at which this XMLToken occurred.

◆ getName()

const string & XMLToken::getName ( ) const

Returns the (unqualified) name of token.

Returns
the (unqualified) name of token.

◆ getNamespaceIndex()

int XMLToken::getNamespaceIndex ( const std::string &  uri) const

Returns the index of an XML namespace declaration based on its URI.

Parameters
uria string, the XML namespace URI of the sought-after namespace.
Returns
the index of the given declaration, or -1 if no such namespace URI is present on this XMLToken object.

◆ getNamespaceIndexByPrefix()

int XMLToken::getNamespaceIndexByPrefix ( const std::string &  prefix) const

Returns the index of an XML namespace declaration based on its prefix.

Parameters
prefixa string, the prefix of the sought-after XML namespace.
Returns
the index of the given declaration, or -1 if no such namespace URI is present on this XMLToken object.

◆ getNamespacePrefix() [1/2]

std::string XMLToken::getNamespacePrefix ( const std::string &  uri) const

Returns the prefix associated with a given XML namespace URI on this token.

Parameters
uria string, the URI of the namespace whose prefix is being sought.
Returns
the prefix of an XML namespace declaration on this XMLToken object.
Note
If there is no XML namespace with the given uri declared on this XMLToken object, this method will return an empty string.

◆ getNamespacePrefix() [2/2]

std::string XMLToken::getNamespacePrefix ( int  index) const

Returns the prefix of the nth XML namespace declaration.

Parameters
indexan integer, position of the required prefix.
Returns
the prefix of an XML namespace declaration in the XMLNamespaces (by position).
Note
If index is out of range, this method will return an empty string. XMLToken::getNamespacesLength() can be used to find out how many namespaces are defined on this XMLToken object.
See also
getNamespacesLength()

◆ getNamespaces()

const XMLNamespaces & XMLToken::getNamespaces ( ) const

Returns the XML namespaces declared for this token.

Returns
the XML namespace declarations for this XML element.

◆ getNamespacesLength()

int XMLToken::getNamespacesLength ( ) const

Returns the number of XML namespaces declared on this token.

Returns
the number of XML namespaces stored in the XMLNamespaces object of this XMLToken object.

◆ getNamespaceURI() [1/2]

std::string XMLToken::getNamespaceURI ( const std::string  prefix = "") const

Returns the URI of an XML namespace with a given prefix.

Parameters
prefixa string, the prefix of the sought-after XML namespace URI.
Returns
the URI of an XML namespace declaration given its prefix.
Note
If there is no XML namespace with the given prefix stored in the XMLNamespaces object of this XMLToken object, this method will return an empty string.

◆ getNamespaceURI() [2/2]

std::string XMLToken::getNamespaceURI ( int  index) const

Returns the URI of the nth XML namespace declared on this token.

Parameters
indexan integer, the position of the sought-after XML namespace URI.
Returns
the URI of the nth XML namespace stored in the XMLNamespaces object in this XMLToken object.
Note
If index is out of range, this method will return an empty string.
See also
getNamespacesLength()

◆ getPrefix()

const string & XMLToken::getPrefix ( ) const

Returns the XML namespace prefix of token.

Returns
the XML namespace prefix of token.
Note
If no XML namespace prefix has been assigned to this token, this method will return an empty string.

◆ getURI()

const string & XMLToken::getURI ( ) const

Returns the XML namespace URI of token.

Returns
the XML namespace URI of token.

◆ hasAttr() [1/3]

bool XMLToken::hasAttr ( const std::string &  name,
const std::string  uri = "" 
) const

Returns true if an attribute with a given name and namespace URI exists.

Parameters
namea string, the name of the attribute being sought.
uria string, the XML namespace URI of the attribute being sought.
Returns
true if an attribute with the given local name and namespace URI exists in the list of attributes on this token object, false otherwise.

◆ hasAttr() [2/3]

bool XMLToken::hasAttr ( const XMLTriple triple) const

Returns true if an attribute defined by a given XMLTriple object exists.

Parameters
triplean XMLTriple object describing the attribute being sought.
Returns
true if an attribute matching the properties of the given XMLTriple object exists in the list of attributes on this token, false otherwise.

◆ hasAttr() [3/3]

bool XMLToken::hasAttr ( int  index) const

Returns true if an attribute with the given index exists.

Parameters
indexan integer, the position of the attribute.
Returns
true if this token object possesses an attribute with the given index, false otherwise.

◆ hasNamespaceNS()

bool XMLToken::hasNamespaceNS ( const std::string &  uri,
const std::string &  prefix 
) const

Returns true if this token has an XML namespace with a given prefix and URI combination.

Parameters
uria string, the URI for the namespace.
prefixa string, the prefix for the namespace.
Returns
true if an XML namespace with the given URI/prefix pair is contained in the XMLNamespaces object of this XMLToken object, false otherwise.

◆ hasNamespacePrefix()

bool XMLToken::hasNamespacePrefix ( const std::string &  prefix) const

Returns true if this token has an XML namespace with a given prefix.

Parameters
prefixa string, the prefix for the XML namespace.
Returns
true if an XML Namespace with the given URI is contained in the XMLNamespaces of this XMLToken, false otherwise.

◆ hasNamespaceURI()

bool XMLToken::hasNamespaceURI ( const std::string &  uri) const

Returns true if this token has an XML namespace with a given URI.

Parameters
uria string, the URI of the XML namespace.
Returns
true if an XML namespace with the given URI is contained in the XMLNamespaces object of this XMLToken object, false otherwise.

◆ isAttributesEmpty()

bool XMLToken::isAttributesEmpty ( ) const

Returns true if this token has no attributes.

Returns
true if the list of attributes on XMLToken object is empty, false otherwise.

◆ isElement()

bool XMLToken::isElement ( ) const

Returns true if this token represents an XML element.

This generic predicate returns true if the element is either a start or end tag, and false if it's a text object. The related methods XMLToken:isStart(), XMLToken::isEnd() and XMLToken::isText() are more specific predicates.

Returns
true if this XMLToken object represents an XML element, false otherwise.
See also
isStart()
isEnd()
isText()

◆ isEnd()

bool XMLToken::isEnd ( ) const

Returns true if this token represents an XML end element.

Returns
true if this XMLToken object represents an XML end element, false otherwise.
See also
isStart()
isElement()
isText()

◆ isEndFor()

bool XMLToken::isEndFor ( const XMLToken element) const

Returns true if this token represents an XML end element for a particular start element.

Parameters
elementXMLToken, the element with which the current object should be compared to determined whether the current object is a start element for the given one.
Returns
true if this XMLToken object represents an XML end tag for the start tag given by element, false otherwise.
See also
isElement()
isStart()
isEnd()
isText()

◆ isEOF()

bool XMLToken::isEOF ( ) const

Returns true if this token is an end of file marker.

Returns
true if this XMLToken object represents the end of the input, false otherwise.
See also
setEOF()

◆ isNamespacesEmpty()

bool XMLToken::isNamespacesEmpty ( ) const

Returns true if there are no namespaces declared on this token.

Returns
true if the XMLNamespaces object stored in this XMLToken token is empty, false otherwise.

◆ isStart()

bool XMLToken::isStart ( ) const

Returns true if this token represents an XML start element.

Returns
true if this XMLToken is an XML start element, false otherwise.
See also
isElement()
isEnd()
isText()

◆ isText()

bool XMLToken::isText ( ) const

Returns true if this token represents an XML text element.

Returns
true if this XMLToken is an XML text element, false otherwise.
See also
isElement()
isStart()
isEnd()

◆ operator=()

XMLToken & XMLToken::operator= ( const XMLToken rhs)

Assignment operator for XMLToken.

Parameters
rhsthe XMLToken object whose values are used as the basis of the assignment.

◆ removeAttr() [1/3]

int XMLToken::removeAttr ( const std::string &  name,
const std::string  uri = "" 
)

Removes an attribute from the XML element represented by this token.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
namea string, the name of the attribute to be removed.
uria string, the XML namespace URI of the attribute to be removed.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are: The value LIBSBML_INDEX_EXCEEDS_SIZE is returned if there is no attribute on this element with the given name (and uri if specified).
See also
hasAttr(const std::string name, const std::string uri) const

◆ removeAttr() [2/3]

int XMLToken::removeAttr ( const XMLTriple triple)

Removes an attribute from the XML element represented by this token.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
triplean XMLTriple describing the attribute to be removed.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are: The value LIBSBML_INDEX_EXCEEDS_SIZE is returned if there is no attribute on this element matching the properties of the given triple.
See also
hasAttr(const XMLTriple& triple) const

◆ removeAttr() [3/3]

int XMLToken::removeAttr ( int  n)

Removes the nth attribute from the XML element represented by this token.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
nan integer the index of the resource to be deleted.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are: The value LIBSBML_INDEX_EXCEEDS_SIZE is returned if there is no attribute on this element at the given index n.
See also
getAttrIndex(const XMLTriple& triple) const
getAttrIndex(const std::string& name, const std::string& uri) const
getAttributesLength()

◆ removeNamespace() [1/2]

int XMLToken::removeNamespace ( const std::string &  prefix)

Removes an XML namespace declaration having a given prefix.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
prefixa string, the prefix of the namespace to be removed.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are: The value LIBSBML_INDEX_EXCEEDS_SIZE is returned if there is no namespace with the given prefix on this element.
See also
getNamespaceIndexByPrefix()

◆ removeNamespace() [2/2]

int XMLToken::removeNamespace ( int  index)

Removes the nth XML namespace declaration.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
indexan integer, the position of the namespace to be removed. The position in this context refers to the position of the namespace in the XMLNamespaces object stored in this XMLToken object. Callers can use one of the getNamespace___() methods to find the index number of a given namespace.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
See also
getNamespaceIndex()
getNamespaceIndexByPrefix()
getNamespacesLength()

◆ setAttributes()

int XMLToken::setAttributes ( const XMLAttributes attributes)

Sets the attributes on the XML element represented by this token.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
attributesan XMLAttributes object to be assigned to this XMLToken object, thereby setting the XML attributes associated with this token.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
Note
This function replaces any existing XMLAttributes object on this XMLToken object with the one given by attributes.

◆ setCharacters()

int XMLToken::setCharacters ( const std::string &  chars)

Sets the characters for this XMLToken.

This method only makes sense for XMLToken objects that contains text. If this method is called on a token that represents an XML start or end tag, it will return the code LIBSBML_OPERATION_FAILED.

Parameters
charsstring, characters to append to the text of this token.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
See also
isText()
isElement()

◆ setEnd()

int XMLToken::setEnd ( )

Declares that this token represents an XML element end tag.

Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
See also
isStart()
isEnd()
Examples
addingEvidenceCodes_2.cpp.

◆ setEOF()

int XMLToken::setEOF ( )

Declares that this token is an end-of-file/input marker.

Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
See also
isEOF()

◆ setNamespaces()

int XMLToken::setNamespaces ( const XMLNamespaces namespaces)

Sets the XML namespaces on this XML element.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
namespacesthe XMLNamespaces object to be assigned to this XMLToken object.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
Note
This function replaces any existing XMLNamespaces object on this XMLToken object with the new one given by namespaces.

◆ setTriple()

int XMLToken::setTriple ( const XMLTriple triple)

Sets the name, namespace prefix and namespace URI of this token.

This operation only makes sense for XML start elements. This method will return LIBSBML_INVALID_XML_OPERATION if this XMLToken object is not an XML start element.
Parameters
triplethe new XMLTriple to use for this XMLToken object. If this XMLToken already had an XMLTriple object stored within it, that object will be replaced.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:

◆ toString()

string XMLToken::toString ( )

Prints a string representation of the underlying token stream.

This method is intended for debugging purposes.

Returns
a text string representing this XMLToken object.

◆ unsetEnd()

int XMLToken::unsetEnd ( )

Declares that this token no longer represents an XML start/end element.

Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are: