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

Class XMLFile

source code

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.

Instance Methods [hide private]
 
__init__(self, **kw)
Create an XMLFile
source code
 
save(self, where=None, obj=None)
Saves the document.
source code
 
saveAs(self, path)
save this time, and all subsequent times, to filename 'path'
source code
 
toxml(self) source code
 
__len__(self)
returns number of child nodes
source code
 
__getitem__(self, idx) source code
Method Details [hide private]

__init__(self, **kw)
(Constructor)

source code 

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

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

source code 

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.