libSBML Python API
5.18.0
|
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.
XMLOutputStream provides a wrapper above output streams to facilitate writing XML. XMLOutputStream keeps track of start and end elements, indentation, XML namespace prefixes, and more. The interface provides features for converting non-text data types into appropriate textual form; this takes the form of overloaded writeAttribute(...)
methods that allow users to simply use the same method with any data type. For example, suppose an element testElement
has two attributes, size
and id
, and the attributes are variables in your code as follows:
Then, the element and the attributes can be written to the standard output stream (provided as cout
in the libSBML language bindings) as follows:
Other classes in SBML take XMLOutputStream objects as arguments, and use that to write elements and attributes seamlessly to the XML output stream.
It is also worth noting that unlike XMLInputStream, XMLOutputStream is actually independent of the underlying XML parsers. It does not use the XML parser libraries at all.
Public Member Functions | |
def | __init__ (self, args) |
Creates a new XMLOutputStream that wraps the given stream . More... | |
def | downIndent (self) |
Decreases the indentation level for this XMLOutputStream. More... | |
def | endElement (self, args) |
This method has multiple variants; they differ in the arguments they accept. More... | |
def | getLibraryName () |
def | getLibraryVersion () |
def | getSBMLNamespaces (self) |
Returns the SBMLNamespaces object attached to this output stream. More... | |
def | getWriteComment () |
def | getWriteTimestamp () |
def | setAutoIndent (self, indent) |
Turns automatic indentation on or off for this XMLOutputStream. More... | |
def | setLibraryName (libraryName) |
sets the name of the library writing the XML More... | |
def | setLibraryVersion (libraryVersion) |
sets the name of the library writing the output More... | |
def | setSBMLNamespaces (self, sbmlns) |
Sets the SBMLNamespaces object associated with this output stream. More... | |
def | setWriteComment (writeComment) |
def | setWriteTimestamp (writeTimestamp) |
def | startElement (self, args) |
This method has multiple variants; they differ in the arguments they accept. More... | |
def | startEndElement (self, args) |
This method has multiple variants; they differ in the arguments they accept. More... | |
def | upIndent (self) |
Increases the indentation level for this XMLOutputStream. More... | |
def | writeAttribute (self, args) |
This method has multiple variants; they differ in the arguments they accept. More... | |
def | writeComment (self, programName, programVersion, writeTimestamp=True) |
Writes an XML comment with the name and version of this program. More... | |
def | writeXMLDecl (self) |
Writes a standard XML declaration to this output stream. More... | |
def libsbml.XMLOutputStream.__init__ | ( | self, | |
args | |||
) |
Creates a new XMLOutputStream that wraps the given stream
.
__init__(ostream stream, string encoding, bool writeXMLDecl, string programName, string programVersion) XMLOutputStream __init__(ostream stream, string encoding, bool writeXMLDecl, string programName) XMLOutputStream __init__(ostream stream, string encoding, bool writeXMLDecl) XMLOutputStream __init__(ostream stream, string encoding) XMLOutputStream __init__(ostream stream) XMLOutputStream
The functionality associated with the programName
and programVersion
arguments concerns an optional comment that libSBML can write at the beginning of the output stream. The comment is intended for human readers of the XML file, and has the following form:
<!-- Created by <program name> version <program version> on yyyy-MM-dd HH:mm with libSBML version <libsbml version>. -->
This program information comment is a separate item from the XML declaration that this method can also write to this output stream. The comment is also not mandated by any SBML specification. This libSBML functionality is provided for the convenience of calling programs, and to help humans trace the origin of SBML files.
LibSBML tries to produce human-readable XML output by automatically indenting the bodies of elements. Callers can manually control indentation further by using the XMLOutputStream::upIndent() and XMLOutputStream::downIndent() methods to increase and decrease, respectively, the current level of indentation in the XML output.
stream | the input stream to wrap. |
encoding | the XML encoding to declare in the output. This value should be "UTF-8" for SBML documents. The default value is "UTF-8" if no value is supplied for this parameter. |
writeXMLDecl | whether to write a standard XML declaration at the beginning of the content written on stream . The default is true . |
programName | an optional program name to write as a comment in the output stream. |
programVersion | an optional version identification string to write as a comment in the output stream. |
def libsbml.XMLOutputStream.downIndent | ( | self | ) |
Decreases the indentation level for this XMLOutputStream.
downIndent()
LibSBML tries to produce human-readable XML output by automatically indenting the bodies of elements. Callers can manually control indentation further by using the XMLOutputStream.upIndent() and XMLOutputStream.downIndent() methods to increase and decrease, respectively, the current level of indentation in the XML output.
def libsbml.XMLOutputStream.endElement | ( | self, | |
args | |||
) |
This method has multiple variants; they differ in the arguments they accept.
endElement(string name, string prefix) endElement(string name) endElement(XMLTriple triple, bool text) endElement(XMLTriple triple)
Each variant is described separately below.
endElement(string name, string prefix = '')
Writes the given XML end element name to this XMLOutputStream.
name | the name of the element. |
prefix | an optional XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) |
parameter
= value
. This is not to be intepreted as a Python keyword argument; the use of a parameter name followed by an equals sign followed by a value is only meant to indicate a default value if the argument is not provided at all. It is not a keyword in the Python sense.endElement(XMLTriple triple, bool text = false)
Writes the given element to the stream.
triple | the XML element to write. |
text | the text to put |
parameter
= value
. This is not to be intepreted as a Python keyword argument; the use of a parameter name followed by an equals sign followed by a value is only meant to indicate a default value if the argument is not provided at all. It is not a keyword in the Python sense. def libsbml.XMLOutputStream.getLibraryName | ( | ) |
getLibraryName() string
def libsbml.XMLOutputStream.getLibraryVersion | ( | ) |
getLibraryVersion() string
def libsbml.XMLOutputStream.getSBMLNamespaces | ( | self | ) |
Returns the SBMLNamespaces object attached to this output stream.
getSBMLNamespaces() SBMLNamespaces
None
if none has been set. def libsbml.XMLOutputStream.getWriteComment | ( | ) |
getWriteComment() bool
def libsbml.XMLOutputStream.getWriteTimestamp | ( | ) |
getWriteTimestamp() bool
def libsbml.XMLOutputStream.setAutoIndent | ( | self, | |
indent | |||
) |
Turns automatic indentation on or off for this XMLOutputStream.
setAutoIndent(bool indent)
indent | if True , automatic indentation is turned on. |
def libsbml.XMLOutputStream.setLibraryName | ( | libraryName | ) |
sets the name of the library writing the XML
libraryName | the name of the library to be used in comments. |
setLibraryName(string libraryName)
def libsbml.XMLOutputStream.setLibraryVersion | ( | libraryVersion | ) |
sets the name of the library writing the output
libraryVersion | the version information as string. |
setLibraryVersion(string libraryVersion)
def libsbml.XMLOutputStream.setSBMLNamespaces | ( | self, | |
sbmlns | |||
) |
Sets the SBMLNamespaces object associated with this output stream.
setSBMLNamespaces(SBMLNamespaces sbmlns)
sbmlns | the namespace object. |
def libsbml.XMLOutputStream.setWriteComment | ( | writeComment | ) |
setWriteComment(bool writeComment)
sets a flag, whether the output stream will write an XML comment at the top of the file. (Enabled by default.)
writeComment | the flag. |
def libsbml.XMLOutputStream.setWriteTimestamp | ( | writeTimestamp | ) |
setWriteTimestamp(bool writeTimestamp)
sets a flag, whether the output stream will write an XML comment with a timestamp at the top of the file. (Enabled by default.)
writeTimestamp | the flag. |
def libsbml.XMLOutputStream.startElement | ( | self, | |
args | |||
) |
This method has multiple variants; they differ in the arguments they accept.
startElement(string name, string prefix) startElement(string name) startElement(XMLTriple triple)
Each variant is described separately below.
startElement(XMLTriple triple)
Writes the given XML start element prefix:name
on this output stream.
triple | the start element to write. |
startElement(string name, string prefix = '')
Writes the given XML start element name to this XMLOutputStream.
name | the name of the element. |
prefix | an optional XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) |
parameter
= value
. This is not to be intepreted as a Python keyword argument; the use of a parameter name followed by an equals sign followed by a value is only meant to indicate a default value if the argument is not provided at all. It is not a keyword in the Python sense. def libsbml.XMLOutputStream.startEndElement | ( | self, | |
args | |||
) |
This method has multiple variants; they differ in the arguments they accept.
startEndElement(string name, string prefix) startEndElement(string name) startEndElement(XMLTriple triple)
Each variant is described separately below.
startEndElement(XMLTriple triple)
Writes the given start element to this output stream.
triple | the XML element to write. |
startEndElement(string name, string prefix = '')
Writes the given XML start and end element name to this XMLOutputStream.
name | the name of the element. |
prefix | an optional XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) |
parameter
= value
. This is not to be intepreted as a Python keyword argument; the use of a parameter name followed by an equals sign followed by a value is only meant to indicate a default value if the argument is not provided at all. It is not a keyword in the Python sense. def libsbml.XMLOutputStream.upIndent | ( | self | ) |
Increases the indentation level for this XMLOutputStream.
upIndent()
LibSBML tries to produce human-readable XML output by automatically indenting the bodies of elements. Callers can manually control indentation further by using the XMLOutputStream.upIndent() and XMLOutputStream.downIndent() methods to increase and decrease, respectively, the current level of indentation in the XML output.
def libsbml.XMLOutputStream.writeAttribute | ( | self, | |
args | |||
) |
This method has multiple variants; they differ in the arguments they accept.
writeAttribute(string name, string value) writeAttribute(string name, string prefix, string value) writeAttribute(XMLTriple triple, string value) writeAttribute(string name, long value) writeAttribute(string name, string prefix, long value) writeAttribute(XMLTriple triple, long value) writeAttribute(string name, bool value) writeAttribute(string name, string prefix, bool value) writeAttribute(XMLTriple triple, bool value) writeAttribute(string name, float value) writeAttribute(string name, string prefix, float value) writeAttribute(XMLTriple triple, float value) writeAttribute(string name, bool value) writeAttribute(string name, string prefix, bool value) writeAttribute(XMLTriple triple, bool value) writeAttribute(string name, bool value) writeAttribute(string name, string prefix, bool value) writeAttribute(XMLTriple triple, bool value) writeAttribute(string name, string prefix, unsigned bool value)
Each variant is described separately below.
writeAttribute(XMLTriple triple, string value)
Writes the given attribute and value to this output stream.
triple | the attribute, in the form of an XMLTriple. |
value | the value of the attribute. |
writeAttribute(string name, string prefix, long value)
Writes the given namespace-prefixed attribute value to this output stream.
name | the name of the attribute. |
prefix | an XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) See other versions of this method for a variant that does not require a prefix. |
value | the value of the attribute. |
writeAttribute(string name, string prefix, string value)
Writes the given namespace-prefixed attribute value to this output stream.
name | the name of the attribute. |
prefix | an XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) See other versions of this method for a variant that does not require a prefix. |
value | the value of the attribute. |
writeAttribute(XMLTriple triple, bool value)
Writes the given attribute and value to this output stream.
triple | the attribute, in the form of an XMLTriple. |
value | the value of the attribute. |
writeAttribute(string name, long value)
Writes the given attribute and value to this output stream.
name | the name of the attribute. |
value | the value of the attribute. |
writeAttribute(XMLTriple triple, long value)
Writes the given attribute and value to this output stream.
triple | the attribute, in the form of an XMLTriple. |
value | the value of the attribute. |
writeAttribute(XMLTriple triple, long value)
Writes the given attribute and value to this output stream.
triple | the attribute, in the form of an XMLTriple. |
value | the value of the attribute. |
writeAttribute(string name, long value)
Writes the given attribute and value to this output stream.
name | the name of the attribute. |
value | the value of the attribute. |
writeAttribute(string name, string value)
Writes the given attribute and value to this output stream.
name | the name of the attribute. |
value | the value of the attribute. |
writeAttribute(string name, string value)
Writes the given attribute and value to this output stream.
name | the name of the attribute. |
value | the value of the attribute. |
writeAttribute(string name, string prefix, long value)
Writes the given namespace-prefixed attribute value to this output stream.
name | the name of the attribute. |
prefix | an XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) See other versions of this method for a variant that does not require a prefix. |
value | the value of the attribute. |
writeAttribute(string name, string prefix, long value)
Writes the given namespace-prefixed attribute value to this output stream.
name | the name of the attribute. |
prefix | an XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) See other versions of this method for a variant that does not require a prefix. |
value | the value of the attribute. |
writeAttribute(string name, string prefix, int value)
Writes the given namespace-prefixed attribute value to this output stream.
name | the name of the attribute. |
prefix | an XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) See other versions of this method for a variant that does not require a prefix. |
value | the value of the attribute. |
writeAttribute(XMLTriple triple, long value)
Writes the given attribute and value to this output stream.
triple | the attribute, in the form of an XMLTriple. |
value | the value of the attribute. |
writeAttribute(string name, int value)
Writes the given attribute and value to this output stream.
name | the name of the attribute. |
value | the value of the attribute. |
writeAttribute(XMLTriple triple, int value)
Writes the given attribute and value to this output stream.
triple | the attribute, in the form of an XMLTriple. |
value | the value of the attribute. |
writeAttribute(string name, bool value)
Writes the given attribute and value to this output stream.
name | the name of the attribute. |
value | the value of the attribute. |
writeAttribute(XMLTriple triple, string value)
Writes the given attribute and value to this output stream.
triple | the attribute, in the form of an XMLTriple. |
value | the value of the attribute. |
writeAttribute(string name, long value)
Writes the given attribute and value to this output stream.
name | the name of the attribute. |
value | the value of the attribute. |
writeAttribute(string name, string prefix, string value)
Writes the given namespace-prefixed attribute value to this output stream.
name | the name of the attribute. |
prefix | an XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) See other versions of this method for a variant that does not require a prefix. |
value | the value of the attribute. |
writeAttribute(string name, string prefix, bool value)
Writes the given namespace-prefixed attribute value to this output stream.
name | the name of the attribute. |
prefix | an XML namespace prefix to write in front of the element name. (The result has the form prefix:name .) See other versions of this method for a variant that does not require a prefix. |
value | the value of the attribute. |
def libsbml.XMLOutputStream.writeComment | ( | self, | |
programName, | |||
programVersion, | |||
writeTimestamp = True |
|||
) |
Writes an XML comment with the name and version of this program.
writeComment(string programName, string programVersion, bool writeTimestamp) writeComment(string programName, string programVersion)
The XML comment has the following form:
<!-- Created by <program name> version <program version> on yyyy-MM-dd HH:mm with libSBML version <libsbml version>. -->
See the class constructor for more information about this program comment.
programName | an optional program name to write as a comment in the output stream. |
programVersion | an optional version identification string to write as a comment in the output stream. |
writeTimestamp | an optional flag indicating that a timestamp should be written. |
parameter
= value
. This is not to be intepreted as a Python keyword argument; the use of a parameter name followed by an equals sign followed by a value is only meant to indicate a default value if the argument is not provided at all. It is not a keyword in the Python sense. def libsbml.XMLOutputStream.writeXMLDecl | ( | self | ) |
Writes a standard XML declaration to this output stream.
writeXMLDecl()
<?xml version='1.0' encoding='UTF-8'?>Note that the SBML specifications require the use of UTF-8 encoding and version 1.0, so for SBML documents, the above is the standard XML declaration.