libSBML Python API  5.18.0
libsbml.XMLInputStream Class Reference
Inheritance diagram for libsbml.XMLInputStream:
[legend]

Detailed Description

An interface to an XML input 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.

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.

Note
The convenience of the XMLInputStream and XMLOutputStream abstraction may be useful for developers interested in creating parsers for other XML formats besides SBML. It can provide developers with a layer above more basic XML parsers, as well as some useful programmatic elements such as XMLToken, XMLError, etc.
See also
XMLOutputStream

Public Member Functions

def __init__ (self, args)
 Creates a new XMLInputStream. More...
 
def containsChild (self, childName, container)
 Predicate returning True if a child token of the specified type occurs within a given container element. More...
 
def determineNumberChildren (self, args)
 Returns the number of child tokens of the given element in this stream. More...
 
def determineNumSpecificChildren (self, childName, container)
 Returns the number of child tokens of the specified type within a given container element. More...
 
def getEncoding (self)
 Returns the encoding of the XML stream. More...
 
def getErrorLog (self)
 Returns the XMLErrorLog used to log parsing problems. More...
 
def getSBMLNamespaces (self)
 Returns the SBMLNamespaces object attached to this XMLInputStream. More...
 
def getVersion (self)
 Returns the version of the XML stream. More...
 
def isEOF (self)
 Returns True if end of file (stream) has been reached. More...
 
def isError (self)
 Returns True if a fatal error occurred while reading from this stream. More...
 
def isGood (self)
 Returns True if the stream is in a good state. More...
 
def next (self)
 Returns the next token on this XML input stream. More...
 
def peek (self)
 Returns the next token without consuming it. More...
 
def setErrorLog (self, log)
 Sets the XMLErrorLog this stream will use to log errors. More...
 
def setSBMLNamespaces (self, sbmlns)
 Sets the SBML namespaces associated with this XML input stream. More...
 
def skipPastEnd (self, element)
 Consume zero or more tokens up to and including the corresponding end element or EOF. More...
 
def skipText (self)
 Consume zero or more tokens up to but not including the next XML element or EOF. More...
 
def toString (self)
 Prints a string representation of the underlying token stream. More...
 

Constructor & Destructor Documentation

def libsbml.XMLInputStream.__init__ (   self,
  args 
)

Creates a new XMLInputStream.

__init__(long  content, bool isFile, string library, XMLErrorLog errorLog)   XMLInputStream
__init__(long  content, bool isFile, string library)   XMLInputStream
__init__(long  content, bool isFile)   XMLInputStream
__init__(long  content)   XMLInputStream
Parameters
contentthe source of the stream.
isFilea 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.
librarythe name of the parser library to use.
errorLogthe XMLErrorLog object to use.
Documentation note:
The native C++ implementation of this method defines a default argument value. In the documentation generated for different libSBML language bindings, you may or may not see corresponding arguments in the method declarations. For example, in Java and C#, a default argument is handled by declaring two separate methods, with one of them having the argument and the other one lacking the argument. However, the libSBML documentation will be identical for both methods. Consequently, if you are reading this and do not see an argument even though one is described, please look for descriptions of other variants of this method near where this one appears in the documentation.

Member Function Documentation

def libsbml.XMLInputStream.containsChild (   self,
  childName,
  container 
)

Predicate returning True if a child token of the specified type occurs within a given container element.

containsChild(string childName, string container)   bool

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.

Parameters
childNamea string representing the name of the child element whose presence is to be determined.
containera string representing the name of the element for which the presence of the child element is to be determined.
Returns
boolean True if a child of type childName occurs within the container element, False otherwise.
Note
This method assumes the stream has been read up to and including the element container.
def libsbml.XMLInputStream.determineNumberChildren (   self,
  args 
)

Returns the number of child tokens of the given element in this stream.

determineNumberChildren(string elementName)   long 
determineNumberChildren()   long

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.

Parameters
elementNamea string representing the name of the element for which the number of children are to be determined.
Returns
a long integer giving the number of children of the elementName specified.
Note
This method assumes the stream has been read up to and including the element elementName.
Owing to the way that language interfaces are created in libSBML, this documentation may show methods that define default values for parameters with text that has the form 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.XMLInputStream.determineNumSpecificChildren (   self,
  childName,
  container 
)

Returns the number of child tokens of the specified type within a given container element.

determineNumSpecificChildren(string childName, string container)   long

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.

Parameters
childNamea string representing the name of the child element whose number is to be determined.
containera string representing the name of the element for which the number of children are to be determined.
Returns
a long integer giving the number of children of type childName within the container element.
Note
This method assumes the stream has been read up to and including the element container.
def libsbml.XMLInputStream.getEncoding (   self)

Returns the encoding of the XML stream.

getEncoding()   string
The encoding is indicated by the xml declaration at the
beginning of an XML document or data stream. The form of this declaration is
<?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'.
Returns
the encoding of the XML stream.
See also
getVersion()
def libsbml.XMLInputStream.getErrorLog (   self)

Returns the XMLErrorLog used to log parsing problems.

getErrorLog()   XMLErrorLog
Returns
the XMLErrorLog used to log XML parse errors and other validation errors (and messages).
def libsbml.XMLInputStream.getSBMLNamespaces (   self)

Returns the SBMLNamespaces object attached to this XMLInputStream.

getSBMLNamespaces()   SBMLNamespaces
Returns
the SBMLNamespaces object or None if none has been set.
def libsbml.XMLInputStream.getVersion (   self)

Returns the version of the XML stream.

getVersion()   string
The version is indicated by the xml declaration at the
beginning of an XML document or data stream. The form of this declaration is
 <?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'.
Returns
the version of the XML stream.
See also
getEncoding()
def libsbml.XMLInputStream.isEOF (   self)

Returns True if end of file (stream) has been reached.

isEOF()   bool
Returns
True if end of file (stream) has been reached, False otherwise.
def libsbml.XMLInputStream.isError (   self)

Returns True if a fatal error occurred while reading from this stream.

isError()   bool
Returns
True if a fatal error occurred while reading from this stream.
def libsbml.XMLInputStream.isGood (   self)

Returns True if the stream is in a good state.

isGood()   bool

The definition of 'good state' is that isEOF() and isError() both return False.

Returns
True if the stream is in a good state, False otherwise.
def libsbml.XMLInputStream.next (   self)

Returns the next token on this XML input stream.

next()   XMLToken

The token is consumed in the process.

Returns
the next XMLToken, or an EOF token (i.e., XMLToken.isEOF() == true).
See also
peek()
def libsbml.XMLInputStream.peek (   self)

Returns the next token without consuming it.

peek()   XMLToken

A subsequent call to either peek() or next() will return the same token.

Returns
the next XMLToken or EOF (XMLToken.isEOF() == true).
See also
next()
def libsbml.XMLInputStream.setErrorLog (   self,
  log 
)

Sets the XMLErrorLog this stream will use to log errors.

setErrorLog(XMLErrorLog log)   int
Returns
integer value indicating success/failure of the function. The possible values returned by this function are:
def libsbml.XMLInputStream.setSBMLNamespaces (   self,
  sbmlns 
)

Sets the SBML namespaces associated with this XML input stream.

setSBMLNamespaces(SBMLNamespaces sbmlns)

This allows this stream to reference the available SBML namespaces being read.

Parameters
sbmlnsthe list of namespaces to use.
def libsbml.XMLInputStream.skipPastEnd (   self,
  element 
)

Consume zero or more tokens up to and including the corresponding end element or EOF.

skipPastEnd(XMLToken element)
Parameters
elementthe element whose end will be sought in the input stream.
def libsbml.XMLInputStream.skipText (   self)

Consume zero or more tokens up to but not including the next XML element or EOF.

skipText()
 
def libsbml.XMLInputStream.toString (   self)

Prints a string representation of the underlying token stream.

toString()   string
Returns
a string representing the underlying XML token stream.
Note
This method is intended for debugging purposes.