Package simplexmlapi :: Module api :: Class SimpleXmlApi
[hide private]
[frames] | no frames]

Class SimpleXmlApi

source code

object --+
         |
        SimpleXmlApi

The main API class, comprising a map of attributes to dotted path names.

Accessing an attribute that has been mapped to a dotted name will return the text value of that node/attribute. If an attribute is passed that isn't in the map, it's passed off to the DotXMLDoc instance, so that the document can be walked manually.

May be subclassed, overriding _map, to provide custom APIs for known XML structures.

Instance Methods [hide private]
 
__init__(self, source='', map=None)
Returns: void
source code
 
add_mapping(self, name, path)
Add a new attribute - dotted name mapping to the instance's map registry.
source code
 
load_source(self, source)
Parse an XML document and set it as this API's target.
source code
 
load_map(self, map)
Update the attribute registry with one or more mappings.
source code
 
del_mapping(self, name)
Remove an attribute mapping from the registry.
source code
 
__getattr__(self, attr) source code
str
_traverse(self, path)
Traverse a dotted path against the XML document in memory and return its text value.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  _map = {}
  _doc = None
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, source='', map=None)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • source (str) - A string containing an XML document
  • map (dict)
Returns:
void
Overrides: object.__init__

add_mapping(self, name, path)

source code 

Add a new attribute - dotted name mapping to the instance's map registry.

Parameters:
  • name (str) - The name of the attribute.
  • path (str) - A dotted name that can be traversed.
Returns:
void

load_source(self, source)

source code 

Parse an XML document and set it as this API's target.

Parameters:
  • source (str) - A string containing an XML document.
Returns:
void

load_map(self, map)

source code 

Update the attribute registry with one or more mappings. Will not remove attributes that currently exist.

Parameters:
  • map (dict) - A dictionary of the form \{'attribute':'dotted.name'\}
Returns:
void

del_mapping(self, name)

source code 

Remove an attribute mapping from the registry.

Parameters:
  • name (str) - The name of the attribute to remove from the registry.
Returns:
void

_traverse(self, path)

source code 

Traverse a dotted path against the XML document in memory and return its text value.

Parameters:
  • path (str) - A dotted path that will resolve to a node or attribute.
Returns: str
The text value of the node.