Module xmlobject :: Class XMLFile
[show private | hide private]
[frames | no frames]

Class XMLFile


Allows an xml file to be viewed and operated on as a python object.

(If you're viewing the epydoc-generated HTML documentation, click the 'show private' link at the top right of this page to see all the methods)

Holds the root node in the .root attribute, also in an attribute with the same name as this root node.
Method Summary
  __init__(self, **kw)
Create an XMLFile
  __getitem__(self, idx)
  __len__(self)
returns number of child nodes
  save(self, where, obj)
Saves the document.
  saveAs(self, path)
save this time, and all subsequent times, to filename 'path'
  toxml(self)

Method Details

__init__(self, **kw)
(Constructor)

Create an XMLFile

Keywords:
  • path - a pathname from which the file can be read
  • file - an open file object from which the raw xml can be read
  • raw - the raw xml itself
  • root - name of root tag, if not reading content
Usage scenarios:
  1. Working with existing content - you must supply input in one of the following ways:
    • 'path' must be an existing file, or
    • 'file' must be a readable file object, or
    • 'raw' must contain raw xml as a string
  2. Creating whole new content - you must give the name of the root tag in the 'root' keyword
Notes:
  • Keyword precedence governing existing content is:
    1. path (if existing file)
    2. file
    3. raw
  • If working with existing content:
    • if the 'root' is given, then the content's toplevel tag MUST match the value given for 'root'
    • trying to _save will raise an exception unless 'path' has been given
  • if not working with existing content:
    • 'root' must be given
    • _save() will raise an exception unless 'path' has been given

__len__(self)
(Length operator)

returns number of child nodes

save(self, where=None, obj=None)

Saves the document.

If argument 'where' is given, saves to it, otherwise tries to save to the original given 'path' (or barfs)

Value can be a string (taken to be a file path), or an open file object.

saveAs(self, path)

save this time, and all subsequent times, to filename 'path'

Generated by Epydoc 2.1 on Sun Apr 16 17:53:16 2006 http://epydoc.sf.net