XMLAttributes Class Reference

List of all members.


Detailed Description

Representation of attributes on an XML node.

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.

Public Member Functions

int add (const std::string &name, const std::string &value, const std::string &namespaceURI="", const std::string &prefix="")
 Adds an attribute (a name/value pair) to this XMLAttributes object, optionally with a prefix and URI defining a namespace.
int add (const XMLTriple &triple, const std::string &value)
 Adds an attribute with the given XMLTriple/value pair to this XMLAttributes set.
int clear ()
 Clears (deletes) all attributes in this XMLAttributes object.
XMLAttributes * clone () const
 Creates and returns a deep copy of this XMLAttributes set.
int getIndex (const std::string &name) const
 Return the index of an attribute with the given name.
int getIndex (const std::string &name, const std::string &uri) const
 Return the index of an attribute with the given local name and namespace URI.
int getIndex (const XMLTriple &triple) const
 Return the index of an attribute with the given XMLTriple.
int getLength () const
 Return the number of attributes in the set.
std::string getName (int index) const
 Return the local name of an attribute in this XMLAttributes set (by position).
int getNumAttributes () const
 Return the number of attributes in the set.
std::string getPrefix (int index) const
 Return the prefix of an attribute in this XMLAttributes set (by position).
std::string getPrefixedName (int index) const
 Return the prefixed name of an attribute in this XMLAttributes set (by position).
std::string getURI (int index) const
 Return the namespace URI of an attribute in this XMLAttributes set (by position).
std::string getValue (int index) const
 Return the value of an attribute in this XMLAttributes set (by position).
std::string getValue (const std::string name) const
 Return an attribute's value by name.
std::string getValue (const std::string name, const std::string uri) const
 Return a value of an attribute with the given local name and namespace URI.
std::string getValue (const XMLTriple &triple) const
 Return a value of an attribute with the given XMLTriple.
bool hasAttribute (int index) const
 Predicate returning true or false depending on whether an attribute with the given index exists in this XMLAttributes.
bool hasAttribute (const std::string name, const std::string uri="") const
 Predicate returning true or false depending on whether an attribute with the given local name and namespace URI exists in this XMLAttributes.
bool hasAttribute (const XMLTriple &triple) const
 Predicate returning true or false depending on whether an attribute with the given XML triple exists in this XMLAttributes.
bool isEmpty () const
 Predicate returning true or false depending on whether this XMLAttributes set is empty.
XMLAttributes & operator= (const XMLAttributes &rhs)
 Assignment operator for XMLAttributes.
bool readInto (const std::string &name, bool &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute name into value.
bool readInto (const XMLTriple &triple, bool &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute with the given XMLTriple into value.
bool readInto (const std::string &name, double &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute name into value.
bool readInto (const XMLTriple &triple, double &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute with the given XMLTriple into value.
bool readInto (const std::string &name, long &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute name into value.
bool readInto (const XMLTriple &triple, long &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute XMLTriple into value.
bool readInto (const std::string &name, int &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute name into value.
bool readInto (const XMLTriple &triple, int &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute with the given XMLTriple into value.
bool readInto (const std::string &name, unsigned int &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute name into value.
bool readInto (const XMLTriple &triple, unsigned int &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute with the given XMLTriple into value.
bool readInto (const std::string &name, std::string &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute name into value.
bool readInto (const XMLTriple &triple, std::string &value, XMLErrorLog *log=NULL, bool required=false) const
 Reads the value for the attribute with the given XMLTriple into value.
int remove (int n)
 Removes an attribute with the given index from this XMLAttributes set.
int remove (const std::string &name, const std::string &uri="")
 Removes an attribute with the given local name and namespace URI from this XMLAttributes set.
int remove (const XMLTriple &triple)
 Removes an attribute with the given XMLTriple from this XMLAttributes set.
int removeResource (int n)
 Removes an attribute with the given index from this XMLAttributes set.
 XMLAttributes ()
 Creates a new empty XMLAttributes set.
 XMLAttributes (const XMLAttributes &orig)
 Copy constructor; creates a copy of this XMLAttributes set.
virtual ~XMLAttributes ()
 Destroys this XMLAttributes set.

Constructor & Destructor Documentation

Creates a new empty XMLAttributes set.

Destroys this XMLAttributes set.

Copy constructor; creates a copy of this XMLAttributes set.


Member Function Documentation

int XMLAttributes::add ( const std::string &  name,
const std::string &  value,
const std::string &  namespaceURI = "",
const std::string &  prefix = "" 
)

Adds an attribute (a name/value pair) to this XMLAttributes object, optionally with a prefix and URI defining a namespace.

Parameters:
namea string, the local name of the attribute.
valuea string, the value of the attribute.
namespaceURIa string, the namespace URI of the attribute.
prefixa string, the prefix of the namespace
Returns:
an integer code indicating the success or failure of the function. The possible values returned by this function are:
Note:
if local name with the same namespace URI already exists in this attribute set, its value and prefix will be replaced.
int XMLAttributes::add ( const XMLTriple &  triple,
const std::string &  value 
)

Adds an attribute with the given XMLTriple/value pair to this XMLAttributes set.

Note:
if local name with the same namespace URI already exists in this attribute set, its value and prefix will be replaced.
Parameters:
triplean XMLTriple, the XML triple of the attribute.
valuea string, the value of the attribute.
Returns:
integer value indicating success/failure of the function. The possible values returned by this function are:

Clears (deletes) all attributes in this XMLAttributes object.

Returns:
integer value indicating success/failure of the function. The possible values returned by this function are:

Creates and returns a deep copy of this XMLAttributes set.

Returns:
a (deep) copy of this XMLAttributes set.
int XMLAttributes::getIndex ( const std::string &  name) const

Return the index of an attribute with the given name.

Note:
A namespace bound to the name is not checked by this function. Thus, if there are multiple attributes with the given local name and different namespaces, the smallest index among those attributes will be returned. XMLAttributes::getIndex(const std::string& name, const std::string& uri) const or XMLAttributes::getIndex(const XMLTriple& triple) const should be used to get an index of an attribute with the given local name and namespace.
Parameters:
namea string, the local name of the attribute for which the index is required.
Returns:
the index of an attribute with the given local name, or -1 if not present.
int XMLAttributes::getIndex ( const std::string &  name,
const std::string &  uri 
) const

Return the index of an attribute with the given local name and namespace URI.

Parameters:
namea string, the local 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 not present.
int XMLAttributes::getIndex ( const XMLTriple &  triple) const

Return the index of an attribute with the given XMLTriple.

Parameters:
triplean XMLTriple, the XML triple of the attribute for which the index is required.
Returns:
the index of an attribute with the given XMLTriple, or -1 if not present.
int XMLAttributes::getLength ( ) const

Return the number of attributes in the set.

Returns:
the number of attributes in this XMLAttributes set.
std::string XMLAttributes::getName ( int  index) const

Return the local name of an attribute in this XMLAttributes set (by position).

Parameters:
indexan integer, the position of the attribute whose local name is required.
Returns:
the local name of an attribute in this list (by position).
Note:
If index is out of range, an empty string will be returned. Use XMLAttributes::hasAttribute(int index) const to test for the attribute existence.

Return the number of attributes in the set.

Returns:
the number of attributes in this XMLAttributes set.

This function is an alias for getLength introduced for consistency with other XML classes.

std::string XMLAttributes::getPrefix ( int  index) const

Return the prefix of an attribute in this XMLAttributes set (by position).

Parameters:
indexan integer, the position of the attribute whose prefix is required.
Returns:
the namespace prefix of an attribute in this list (by position).
Note:
If index is out of range, an empty string will be returned. Use XMLAttributes::hasAttribute(int index) const to test for the attribute existence.
std::string XMLAttributes::getPrefixedName ( int  index) const

Return the prefixed name of an attribute in this XMLAttributes set (by position).

Parameters:
indexan integer, the position of the attribute whose prefixed name is required.
Returns:
the prefixed name of an attribute in this list (by position).
Note:
If index is out of range, an empty string will be returned. Use XMLAttributes::hasAttribute(int index) const to test for attribute existence.
std::string XMLAttributes::getURI ( int  index) const

Return the namespace URI of an attribute in this XMLAttributes set (by position).

Parameters:
indexan integer, the position of the attribute whose namespace URI is required.
Returns:
the namespace URI of an attribute in this list (by position).
Note:
If index is out of range, an empty string will be returned. Use XMLAttributes::hasAttribute(int index) const to test for attribute existence.
std::string XMLAttributes::getValue ( int  index) const

Return the value of an attribute in this XMLAttributes set (by position).

Parameters:
indexan integer, the position of the attribute whose value is required.
Returns:
the value of an attribute in the list (by position).
Note:
If index is out of range, an empty string will be returned. Use XMLAttributes::hasAttribute(int index) const to test for attribute existence.
std::string XMLAttributes::getValue ( const std::string  name) const

Return an attribute's value by name.

Parameters:
namea string, the local name of the attribute whose value is required.
Returns:
The attribute value as a string.
Note:
If an attribute with the given local name does not exist, an empty string will be returned. Use XMLAttributes::hasAttribute(const std::string name, const std::string uri) const to test for attribute existence. A namespace bound to the local name is not checked by this function. Thus, if there are multiple attributes with the given local name and different namespaces, the value of an attribute with the smallest index among those attributes will be returned. XMLAttributes::getValue(const std::string name) const or XMLAttributes::getValue(const XMLTriple& triple) const should be used to get a value of an attribute with the given local name and namespace.
std::string XMLAttributes::getValue ( const std::string  name,
const std::string  uri 
) const

Return a value of an attribute with the given local name and namespace URI.

Parameters:
namea string, the local name of the attribute whose value is required.
uria string, the namespace URI of the attribute.
Returns:
The attribute value as a string.
Note:
If an attribute with the given local name and namespace URI does not exist, an empty string will be returned. Use XMLAttributes::hasAttribute(const std::string name, const std::string uri) const to test for attribute existence.
std::string XMLAttributes::getValue ( const XMLTriple &  triple) const

Return a value of an attribute with the given XMLTriple.

Parameters:
triplean XMLTriple, the XML triple of the attribute whose value is required.
Returns:
The attribute value as a string.
Note:
If an attribute with the given XMLTriple does not exist, an empty string will be returned. Use XMLAttributes::hasAttribute(const XMLTriple& triple) const to test for attribute existence.
bool XMLAttributes::hasAttribute ( int  index) const

Predicate returning true or false depending on whether an attribute with the given index exists in this XMLAttributes.

Parameters:
indexan integer, the position of the attribute.
Returns:
true if an attribute with the given index exists in this XMLAttributes, false otherwise.
bool XMLAttributes::hasAttribute ( const std::string  name,
const std::string  uri = "" 
) const

Predicate returning true or false depending on whether an attribute with the given local name and namespace URI exists in this XMLAttributes.

Parameters:
namea string, the local name of the attribute.
uria string, the namespace URI of the attribute.
Returns:
true if an attribute with the given local name and namespace URI exists in this XMLAttributes, false otherwise.
bool XMLAttributes::hasAttribute ( const XMLTriple &  triple) const

Predicate returning true or false depending on whether an attribute with the given XML triple exists in this XMLAttributes.

Parameters:
triplean XMLTriple, the XML triple of the attribute
Returns:
true if an attribute with the given XML triple exists in this XMLAttributes, false otherwise.
bool XMLAttributes::isEmpty ( ) const

Predicate returning true or false depending on whether this XMLAttributes set is empty.

Returns:
true if this XMLAttributes set is empty, false otherwise.
XMLAttributes & XMLAttributes::operator= ( const XMLAttributes &  rhs)

Assignment operator for XMLAttributes.

bool XMLAttributes::readInto ( const std::string &  name,
bool &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute name into value.

If the given local name was not found or value could be interpreted as a boolean, value is not modified.

According to the W3C XML Schema, valid boolean values are: "true", "false", "1", and "0" (case-insensitive). For more information, see: http://www.w3.org/TR/xmlschema-2/#boolean

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
namea string, the local name of the attribute.
valuea boolean, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
Note:
A namespace bound to the given local name is not checked by this function. XMLAttributes::readInto(const XMLTriple, bool&, ...) const should be used to read a value for an attribute name with a prefix and namespace.
bool XMLAttributes::readInto ( const XMLTriple &  triple,
bool &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute with the given XMLTriple into value.

If the XMLTriple was not found or value could be interpreted as a boolean, value is not modified.

According to the W3C XML Schema, valid boolean values are: "true", "false", "1", and "0" (case-insensitive). For more information, see: http://www.w3.org/TR/xmlschema-2/#boolean

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
triplean XMLTriple, the XML triple of the attribute.
valuea boolean, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
bool XMLAttributes::readInto ( const std::string &  name,
double &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute name into value.

If the given local name was not found or value could be interpreted as a double, value is not modified.

According to the W3C XML Schema, valid doubles are the same as valid doubles for C and the special values "INF", "-INF", and "NaN" (case-sensitive). For more information, see: http://www.w3.org/TR/xmlschema-2/#double

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
namea string, the local name of the attribute.
valuea double, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
Note:
A namespace bound to the given local name is not checked by this function. XMLAttributes::readInto(const XMLTriple, double&, ...) const should be used to read a value for an attribute name with a prefix and namespace.
bool XMLAttributes::readInto ( const XMLTriple &  triple,
double &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute with the given XMLTriple into value.

If the triple was not found or value could be interpreted as a double, value is not modified.

According to the W3C XML Schema, valid doubles are the same as valid doubles for C and the special values "INF", "-INF", and "NaN" (case-sensitive). For more information, see: http://www.w3.org/TR/xmlschema-2/#double

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
triplean XMLTriple, the XML triple of the attribute.
valuea double, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
bool XMLAttributes::readInto ( const std::string &  name,
long &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute name into value.

If the given local name was not found or value could be interpreted as an long, value is not modified.

According to the W3C XML Schema valid integers include zero, *all* positive and *all* negative whole numbers. For practical purposes, we limit values to what can be stored in a long. For more information, see: http://www.w3.org/TR/xmlschema-2/#integer

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
namea string, the local name of the attribute.
valuea long, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
Note:
A namespace bound to the given local name is not checked by this function. XMLAttributes::readInto(const XMLTriple, long&, ...) const should be used to read a value for an attribute name with a prefix and namespace.
bool XMLAttributes::readInto ( const XMLTriple &  triple,
long &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute XMLTriple into value.

If the XMLTriple was not found or value could be interpreted as a long, value is not modified.

According to the W3C XML Schema valid integers include zero, *all* positive and *all* negative whole numbers. For practical purposes, we limit values to what can be stored in a long. For more information, see: http://www.w3.org/TR/xmlschema-2/#integer

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
triplean XMLTriple, the XML triple of the attribute.
valuea long, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
bool XMLAttributes::readInto ( const std::string &  name,
int &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute name into value.

If the given local name was not found or value could be interpreted as an int, value is not modified.

According to the W3C XML Schema valid integers include zero, *all* positive and *all* negative whole numbers. For practical purposes, we limit values to what can be stored in a int. For more information, see: http://www.w3.org/TR/xmlschema-2/#integer

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
namea string, the local name of the attribute.
valuean integer, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
Note:
A namespace bound to the given local name is not checked by this function. XMLAttributes::readInto(const XMLTriple, int&, ...) const should be used to read a value for an attribute name with a prefix and namespace.
bool XMLAttributes::readInto ( const XMLTriple &  triple,
int &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute with the given XMLTriple into value.

If the XMLTriple was not found or value could be interpreted as an int, value is not modified.

According to the W3C XML Schema valid integers include zero, *all* positive and *all* negative whole numbers. For practical purposes, we limit values to what can be stored in a int. For more information, see: http://www.w3.org/TR/xmlschema-2/#integer

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
triplean XMLTriple, the XML triple of the attribute.
valuean integer, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
bool XMLAttributes::readInto ( const std::string &  name,
unsigned int &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute name into value.

If the given local name was not found or value could be interpreted as an unsigned int, value is not modified.

According to the W3C XML Schema valid integers include zero, *all* positive and *all* negative whole numbers. For practical purposes, we limit values to what can be stored in a unsigned int. For more information, see: http://www.w3.org/TR/xmlschema-2/#integer

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
namea string, the local name of the attribute.
valuean unsigned integer, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
Note:
A namespace bound to the given local name is not checked by this function. XMLAttributes::readInto(const XMLTriple, unsigned int&, ...) const should be used to read a value for an attribute name with a prefix and namespace.
bool XMLAttributes::readInto ( const XMLTriple &  triple,
unsigned int &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute with the given XMLTriple into value.

If the XMLTriple was not found or value could be interpreted as an unsigned int, value is not modified.

According to the W3C XML Schema valid integers include zero, *all* positive and *all* negative whole numbers. For practical purposes, we limit values to what can be stored in a unsigned int. For more information, see: http://www.w3.org/TR/xmlschema-2/#integer

If an XMLErrorLog is passed in datatype format errors are logged. If required is true, missing attributes are also logged.

Parameters:
triplean XMLTriple, the XML triple of the attribute.
valuean unsigned integer, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
bool XMLAttributes::readInto ( const std::string &  name,
std::string &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute name into value.

If the given local name was not found, value is not modified.

If an XMLErrorLog is passed in and required is true, missing attributes are logged.

Parameters:
namea string, the local name of the attribute.
valuea string, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
Note:
A namespace bound to the given local name is not checked by this function. XMLAttributes::readInto(const XMLTriple, std::string&, ...) const should be used to read a value for an attribute name with a prefix and namespace.
bool XMLAttributes::readInto ( const XMLTriple &  triple,
std::string &  value,
XMLErrorLog *  log = NULL,
bool  required = false 
) const

Reads the value for the attribute with the given XMLTriple into value.

If the XMLTriple was not found, value is not modified.

If an XMLErrorLog is passed in and required is true, missing attributes are logged.

Parameters:
triplean XMLTriple, the XML triple of the attribute.
valuea string, the value of the attribute.
logan XMLErrorLog, the error log.
requireda boolean, indicating whether the attribute is required.
Returns:
true if the attribute was read into value, false otherwise.
int XMLAttributes::remove ( int  n)

Removes an attribute with the given index from this XMLAttributes set.

(This function is an alias of XMLAttributes::removeResource() ).

Parameters:
nan integer the index of the resource to be deleted
Returns:
integer value indicating success/failure of the function. The possible values returned by this function are:
int XMLAttributes::remove ( const std::string &  name,
const std::string &  uri = "" 
)

Removes an attribute with the given local name and namespace URI from this XMLAttributes set.

Parameters:
namea string, the local name of the attribute.
uria string, the namespace URI of the attribute.
Returns:
integer value indicating success/failure of the function. The possible values returned by this function are:
int XMLAttributes::remove ( const XMLTriple &  triple)

Removes an attribute with the given XMLTriple from this XMLAttributes set.

Parameters:
triplean XMLTriple, the XML triple of the attribute.
Returns:
integer value indicating success/failure of the function. The possible values returned by this function are:

Removes an attribute with the given index from this XMLAttributes set.

Parameters:
nan integer the index of the resource to be deleted
Returns:
integer value indicating success/failure of the function. The possible values returned by this function are:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines