Basic XML Components¶
- psims.xml.element(xml_file, _tag_name, *args, **kwargs)[source]¶
Construct and immediately write a subclass instance of
TagBase
with the given tag name. All other arguments are forwarded to theTagBase
constructor- Parameters
xml_file (
XMLWriterMixin
) – The XML writer to write to_tag_name (str) – The name of the tag type to create
*args – Arbitrary arguments for the tag
**kwargs – Key word arguments for the tag
- psims.xml._element(_tag_name, *args, **kwargs)[source]¶
Construct a subclass instance of
TagBase
with the given tag name. All other arguments are forwarded to theTagBase
constructor
- class psims.xml.TagBase(tag_name=None, text='', **attrs)[source]¶
Represent a single XML element with arbitrary attributes.
Mocks the
Mapping
interface
- class psims.xml.CVParam(accession=None, name=None, ref=None, value=None, **attrs)[source]¶
Represents a
<cvParam />
Note
This element holds additional data or annotation. Only controlled values are allowed here
XSD Description
This element holds additional data or annotation. Only controlled values are allowed here.
- class psims.xml.UserParam(accession=None, name=None, ref=None, value=None, **attrs)[source]¶
Represents a
<userParam />
elementNote
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead
XSD Description
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead
- class psims.xml.CV(full_name, id, uri, version=None, resolver=None, **kwargs)[source]¶
Represent a Controlled Vocabulary associated with the current document.
The controlled vocabulary referenced must specify a URI that will be used to either download the definitions from, to be matched to a cache of pre-built vocabularies, or to be matched with a set of special resolution rules for handled by the
resolver
.This object acts as a lazy-loading proxy for
ControlledVocabulary
.- full_name¶
The full name of the controlled vocabulary, which may or may not be identical to the
id
- Type
- resolver¶
The resolver which will handle all requests for this controlled vocabulary
- Type
VocabularyResolver
- vocabulary¶
The parsed term graph defining this vocabulary
- Type
XSD Description
Information about an ontology or CV source and a short 'lookup' tag to refer to.
- class psims.xml.ProvidedCV(id, uri, converter=<function identity>, **kwargs)[source]¶
A wrapper around another object that provides the same basic interface as
CV
from that object, provided through theconverter
function- converter¶
A function that converts elements of the provided vocabulary into something matching the
Entity
interface.- Type
Callable
- class psims.xml.XMLWriterMixin[source]¶
A mixin class to provide methods for writing XML elements and aggregate Components.
- writer¶
The low-level XML writer used by
xmlfile
- Type
lxml.etree._IncrementalFileWriter
- element(element_name, **kwargs)[source]¶
Construct and immediately open a subclass instance of
TagBase
with the given tag name. All other arguments are forwarded to theTagBase
constructor.- Parameters
element_name (str) – The name of the tag type to create
*args – Arbitrary arguments for the tag
**kwargs – Key word arguments for the tag
See also
- class psims.xml.XMLDocumentWriter(outfile, close=None, encoding=None, **kwargs)[source]¶
A base class for types which are used to write complete XML documents.
- outfile¶
A writable file object
- Type
file
- xmlfile¶
The XML formatter
- Type
lxml.etree.xmlfile
- controlled_vocabularies()[source]¶
Write out the <cvList> element and all its children, including both this format’s default controlled vocabularies and those passed as arguments to this method.this
This method requires writing to have begun.
- element(element_name, **kwargs)¶
Construct and immediately open a subclass instance of
TagBase
with the given tag name. All other arguments are forwarded to theTagBase
constructor.- Parameters
element_name (str) – The name of the tag type to create
*args – Arbitrary arguments for the tag
**kwargs – Key word arguments for the tag
See also
- end(exc_type=None, exc_value=None, traceback=None)[source]¶
Ends the XML document, and flushes and closes the file if appropriate.
- format(outfile=None)[source]¶
This method is deprecated. Previously, the serialization process did not indent the XML in-place and the lxml pretty printer had to be invoked separately. With the addition of
XMLFormattingStreamWriter
, the XML stream is formatted in-place as it is being streamed to file.
- static toplevel_tag()[source]¶
Overridable method to construct the appropriate tag for
toplevel
- Returns
- Return type
- write(*args, **kwargs)¶
Either write a complete XML sub-tree or add free text to the file stream
- Parameters
arg (str or
lxml.etree.Element
) – The entity to be written out.