Package musicbrainz2 :: Module wsxml :: Class MbXmlParser

[frames] | no frames]

# Class MbXmlParser

source code

    object --+
             |
            MbXmlParser

A parser for the Music Metadata XML format.

This parser supports all basic features and extensions defined by MusicBrainz, including unlimited document nesting. By default it reads an XML document from a file-like object (stream) and returns an object tree representing the document using classes from musicbrainz2.model.

The implementation tries to be as permissive as possible. Invalid contents are skipped, but documents have to be well-formed and using the correct namespace. In case of unrecoverable errors, a ParseError exception is raised.

See Also: The Music Metadata XML Format

Instance Methods

__init__(self, factory=<musicbrainz2.wsxml.DefaultFactory object>) Constructor. | source code

parse(self, inStream) Parses the MusicBrainz web service XML. | source code

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, factory=<musicbrainz2.wsxml.DefaultFactory object>)
(Constructor)

source code

Constructor.

The `factory` parameter has be an instance of DefaultFactory or a subclass of it. It is used by parse to obtain objects from musicbrainz2.model to build resulting object tree. If you supply your own factory, you have to make sure all returned objects have the same interface as their counterparts from musicbrainz2.model.

Parameters:
  - `factory` - an object factory
Overrides: object.__init__

### parse(self, inStream)

source code

Parses the MusicBrainz web service XML.

Returns a Metadata object representing the parsed XML or raises a ParseError exception if the data was malformed. The parser tries to be liberal and skips invalid content if possible.

Note that an `IOError` may be raised if there is a problem reading `inStream`.

Parameters:
  - `inStream` - a file-like object
Returns:
  a Metadata object (never None)
Raises:
  - `ParseError` - if the document is not valid
  - `IOError` - if reading from the stream failed