libSBML C++ API
5.20.4
|
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.
SBML content is serialized using XML; the resulting data can be stored and read to/from a file or data stream. Low-level XML parsers such as Xerces provide facilities to read XML data. To permit the use of different XML parsers (Xerces, Expat or libxml2), libSBML implements an abstraction layer. XMLInputStream and XMLOutputStream are two parts of that abstraction layer.
XMLInputStream is an interface to a file or text string containing XML. It wraps the content to be read, as well as the low-level XML parser to be used and an XMLErrorLog to record errors and other issues (if any arise). Internally, the content will be in the form of either a pointer to a file name or a character string; XMLInputStream knows the form of the content and acts appropriately. Other libSBML object classes use XMLInputStream as their interface for all read operations on the XML data. XMLInputStream provides the functionality to extract data in the form of XMLToken objects. It logs any errors encountered while reading. It also keeps track of whether a read operation has failed irrecoverably or determines whether it is safe to continue reading.
SBMLNamespaces objects can be associated with an XMLInputStream; this facilitates logging errors related to reading XML attributes and elements that may only be relevant to particular Level and Version combinations of SBML.
Public Member Functions | |
bool | containsChild (const std::string &childName, const std::string &container) |
Predicate returning true if a child token of the specified type occurs within a given container element. More... | |
unsigned int | determineNumberChildren (const std::string elementName="") |
Returns the number of child tokens of the given element in this stream. More... | |
unsigned int | determineNumSpecificChildren (const std::string &childName, const std::string &container) |
Returns the number of child tokens of the specified type within a given container element. More... | |
const std::string & | getEncoding () |
Returns the encoding of the XML stream. More... | |
XMLErrorLog * | getErrorLog () |
Returns the XMLErrorLog used to log parsing problems. More... | |
SBMLNamespaces * | getSBMLNamespaces () |
Returns the SBMLNamespaces object attached to this XMLInputStream. More... | |
const std::string & | getVersion () |
Returns the version of the XML stream. More... | |
bool | isEOF () const |
Returns true if end of file (stream) has been reached. More... | |
bool | isError () const |
Returns true if a fatal error occurred while reading from this stream. More... | |
bool | isGood () const |
Returns true if the stream is in a good state. More... | |
XMLToken | next () |
Returns the next token on this XML input stream. More... | |
const XMLToken & | peek () |
Returns the next token without consuming it. More... | |
int | setErrorLog (XMLErrorLog *log) |
Sets the XMLErrorLog this stream will use to log errors. More... | |
void | setSBMLNamespaces (SBMLNamespaces *sbmlns) |
Sets the SBML namespaces associated with this XML input stream. More... | |
void | skipPastEnd (const XMLToken &element) |
Consume zero or more tokens up to and including the corresponding end element or EOF. More... | |
void | skipText () |
Consume zero or more tokens up to but not including the next XML element or EOF. More... | |
std::string | toString () |
Prints a string representation of the underlying token stream. More... | |
XMLInputStream (const char *content, bool isFile=true, const std::string library="", XMLErrorLog *errorLog=NULL) | |
Creates a new XMLInputStream. More... | |
virtual | ~XMLInputStream () |
Destroys this XMLInputStream. More... | |
XMLInputStream::XMLInputStream | ( | const char * | content, |
bool | isFile = true , |
||
const std::string | library = "" , |
||
XMLErrorLog * | errorLog = NULL |
||
) |
Creates a new XMLInputStream.
content | the source of the stream. |
isFile | a boolean flag to indicate whether content is a file name. If true , content is assumed to be the file from which the XML content is to be read. If false , content is taken to be a string that is the content to be read. |
library | the name of the parser library to use. |
errorLog | the XMLErrorLog object to use. |
|
virtual |
Destroys this XMLInputStream.
bool XMLInputStream::containsChild | ( | const std::string & | childName, |
const std::string & | container | ||
) |
Predicate returning true
if a child token of the specified type occurs within a given container element.
This method allows information from the input stream to be determined without the need to actually read and consume the tokens in the stream. It returns true
if the childName
element occurs at any point within the element specified by container
.
childName | a string representing the name of the child element whose presence is to be determined. |
container | a string representing the name of the element for which the presence of the child element is to be determined. |
true
if a child of type childName
occurs within the container
element, false
otherwise.container
. unsigned int XMLInputStream::determineNumberChildren | ( | const std::string | elementName = "" | ) |
Returns the number of child tokens of the given element in this stream.
This method allows information from the input stream to be determined without the need to actually read and consume the tokens in the stream. It returns the number of child elements of the element represented by the elementName
, i.e., the number of child elements encountered before the closing tag for the elementName
supplied.
If no elementName
is supplied or it is an empty string, then as a special case, this method assumes the element is a MathML apply
element followed by a function name.
elementName | a string representing the name of the element for which the number of children are to be determined. |
elementName
specified.elementName
. unsigned int XMLInputStream::determineNumSpecificChildren | ( | const std::string & | childName, |
const std::string & | container | ||
) |
Returns the number of child tokens of the specified type within a given container element.
This method allows information from the input stream to be determined without the need to actually read and consume the tokens in the stream. It returns the number of child elements of the childName
element within the element specified by container
. In other words, it counts the number of childName
elements encountered before the closing tag for the container
supplied.
childName | a string representing the name of the child element whose number is to be determined. |
container | a string representing the name of the element for which the number of children are to be determined. |
childName
within the container
element.container
. const std::string& XMLInputStream::getEncoding | ( | ) |
Returns the encoding of the XML stream.
<?xml version="1.0" encoding="UTF-8"?>Note that the SBML specifications require the use of UTF-8 encoding, so for SBML documents, the value returned by this method will always be the string
"UTF-8"
.XMLErrorLog* XMLInputStream::getErrorLog | ( | ) |
Returns the XMLErrorLog used to log parsing problems.
SBMLNamespaces* XMLInputStream::getSBMLNamespaces | ( | ) |
Returns the SBMLNamespaces object attached to this XMLInputStream.
NULL
if none has been set. const std::string& XMLInputStream::getVersion | ( | ) |
Returns the version of the XML stream.
<?xml version="1.0" encoding="UTF-8"?>Note that the SBML specifications require the use of version 1.0, so for SBML documents, the value returned by this method will always be the string
"1.0"
.bool XMLInputStream::isEOF | ( | ) | const |
Returns true
if end of file (stream) has been reached.
true
if end of file (stream) has been reached, false
otherwise. bool XMLInputStream::isError | ( | ) | const |
Returns true
if a fatal error occurred while reading from this stream.
true
if a fatal error occurred while reading from this stream. bool XMLInputStream::isGood | ( | ) | const |
XMLToken XMLInputStream::next | ( | ) |
Returns the next token on this XML input stream.
The token is consumed in the process.
XMLToken.isEOF() == true
).const XMLToken& XMLInputStream::peek | ( | ) |
Returns the next token without consuming it.
A subsequent call to either peek() or next() will return the same token.
int XMLInputStream::setErrorLog | ( | XMLErrorLog * | log | ) |
Sets the XMLErrorLog this stream will use to log errors.
void XMLInputStream::setSBMLNamespaces | ( | SBMLNamespaces * | sbmlns | ) |
Sets the SBML namespaces associated with this XML input stream.
This allows this stream to reference the available SBML namespaces being read.
sbmlns | the list of namespaces to use. |
void XMLInputStream::skipPastEnd | ( | const XMLToken & | element | ) |
Consume zero or more tokens up to and including the corresponding end element or EOF.
element | the element whose end will be sought in the input stream. |
void XMLInputStream::skipText | ( | ) |
Consume zero or more tokens up to but not including the next XML element or EOF.
std::string XMLInputStream::toString | ( | ) |
Prints a string representation of the underlying token stream.