module xmlhelper.xml_tree

Inheritance diagram of pyrsslocal.xmlhelper.xml_tree

Short summary

module pyrsslocal.xmlhelper.xml_tree

parsing XML

source on GitHub

Classes

class

truncated documentation

XMLHandlerDict

Overloads functions about XML, it produces objects at the end we assume the file contains a list of objects.

XMLIterParser

To use a parser like an iterator. Example:

Methods

method

truncated documentation

__init__

__init__

_prepare_stringio

prepare the StringIO stream

characters

Adds characters.

endElement

After a tag.

parse

Parses an XML document from a URL or an InputSource.

startElement

When enters a section.

Documentation

parsing XML

source on GitHub

class pyrsslocal.xmlhelper.xml_tree.XMLHandlerDict(no_content=False)

Bases: ContentHandler

Overloads functions about XML, it produces objects at the end we assume the file contains a list of objects.

source on GitHub

Parameters:

no_content – avoid loading the content of every record

source on GitHub

__init__(no_content=False)
Parameters:

no_content – avoid loading the content of every record

source on GitHub

_prepare_stringio()

prepare the StringIO stream

source on GitHub

characters(content)

Adds characters.

source on GitHub

endElement(name)

After a tag.

source on GitHub

startElement(name, attrs)

When enters a section.

source on GitHub

class pyrsslocal.xmlhelper.xml_tree.XMLIterParser(namespaceHandling=0, bufsize=131072)

Bases: ExpatParser

To use a parser like an iterator. Example:

zxml = """
        <mixed engine___="conf1" fid="3" grade___="Fair" query___="queryA" rank="3">
          <urls>
          <url___>http://www.shop.com/Soloxine_1_0mg_Tab-181378988-214010464-p!.shtml</url___>
          <url___>http://fake</url___>
          </urls>
        </mixed>
        <mixed engine___="conf1" fid="4" grade___="Good" query___="queryA" rank="4"
               url___="http%3A//www.lamars.com/products/nutrition.html" />
       """

zxml = "<root>%s</root>" % zxml
f = StringIO.StringIO (zxml)
assert len(f.getvalue()) > 0

parser = XMLIterParser()
handler = XMLHandlerDict(no_content = False)
parser.setContentHandler(handler)
nb = 0
for o in parser.parse(f) :
    assert o["query___"] == "queryA"
    nb += 1
assert nb > 0

source on GitHub

__init__(namespaceHandling=0, bufsize=131072)
parse(source)

Parses an XML document from a URL or an InputSource.

Parameters:

source – a file or a stream

source on GitHub