return to index
xsdb project page with download links
xFeedMe xsdb resources

Python implementation notes

The python xsdbXML framework allows programs to use the XSDBxml framework in Python programs and also provides a number of useful related python scripts.

The python implementation of the xsdbXML framework requires an installation of Python 2.3 or higher. In addition to this the framework will run faster if the Python installation includes the pyRXP extension module available from

To install the XsdbXMLpy framework within your Python installation run the xsdbXML/ script as follows from a command prompt

   ...xsdbXML> install
When the installation successfully completes you may test the installation by running in the examples directory
   ...xsdbXML> cd examples
This should produce a large amount of output concluding with something like
    <!-- same/different test passes -->
    <!-- ran 5 tests -->
    ...examples> _
If the script cannot be found then please make sure that your command search path environment variable includes the standard directory for installed python scripts. On my Windows 2000 machine this directory is C:\Python23\Scripts and my path environment variable includes this path at the very end.
    prompt> echo %PATH%
    ...lots of stuff...;C:\Python23;C:\Python23\Scripts;
If the script completes with no exception when run from the examples directory then your xsdbXML framework installation is ready to go.

Running queries from the python prompt: We may run the queries from the python prompt using the xsdbXML Python applications program interface. The interaction below creates a query string, initializes a query object from a query string, and displays the query result in three different formats: as a string, as a sequence of dictionaries, and as a sequence of tuples.

>>> from xsdbXMLpy import interp
>>> query = """
...   <query>
...     <consult href="accesses.xsdb">
...       <s at="page">index.html</s>
...     </consult>
...   </query>"""
>>> from xsdbXMLpy import interp
>>> q = interp.Query(query)
>>> print q.stringResult()
       <i at="hits">3300</i>
       <i at="month">2</i>
       <s at="page">index.html</s>
       <i at="hits">1950</i>
       <i at="month">3</i>
       <s at="page">index.html</s>
       <i at="hits">2100</i>
       <i at="month">1</i>
       <s at="page">index.html</s>
>>> for D in q.dictionaries():
...     print D
{'hits': 3300, 'page': 'index.html', 'month': 2}
{'hits': 1950, 'page': 'index.html', 'month': 3}
{'hits': 2100, 'page': 'index.html', 'month': 1}
>>> for tup in q.tuples():
...     print tup
(3300, 2, 'index.html')
(1950, 3, 'index.html')
(2100, 1, 'index.html')
Note that since the query did not specify the row ordering the order of the dictionaries and tuples is not deterministic and since the attribute order was not specified either the ordering of values within the tuples defaults to alphabetical by attribute name.

Queries within programs:

A python program can use the same API illustrated above to query xsdbXML information. The primary features of the Python xsdb API may be summarized as follows:
   from xsdbXMLpy import interp   # use the primary interface module interp.
   q = interp.Query(queryText)    # create a query object from the string queryText.
   Dicts = q.dictionaries()       # extract the query result as a sequence of dictionaries.
   Tups = q.tuples()              # extract the query result as a sequence of tuples.
   S = q.stringResult()           # extract the query result as an xsdb string representation.
   text = q.getIdContent(id)      # fetch the contents of the object named by the id.
End of Python implementation notes
return to index