letzte Aktualisierung: 21. März 2007
db2xml
default ] [ fancy ]

db2xml (depracted! see foss)

db2xml provides a sax-handler and a standalone program to execute sql queries embedded in xml files and replace the query string with the query's result.

Requirements

Download

Unix/Linux: db2xml.tgz

Examples

simple query

input:
<?xml version="1.0" encoding="ISO-8859-1"?> <persons xmlns:v="http://www.loisch.de/software/db2xml.html#v" xmlns:d="http://www.loisch.de/software/db2xml.html#d"> <v:for-each> <v:query> SELECT street, zipcode, city FROM address </v:query> <person> <v:row-values/> </person> </v:for-each> </persons>
output:
<?xml version="1.0" encoding="ISO-8859-1"?> <persons xmlns:v="http://www.loisch.de/software/db2xml.html#v" xmlns:d="http://www.loisch.de/software/db2xml.html#d"> <person> <street>Wallstr. 15</street> <zipcode>79098</zipcode> <city>Freiburg</city> </person> <person> <street>Meisenweg 7</street> <zipcode>79211</zipcode> <city>Denzlingen</city> </person> </persons>

advanced usage

database schema:
CREATE TABLE category ( cid integer primary key, name varchar(30) not null unique, parent integer null references category(cid) ); CREATE TABLE link ( lid integer primary key, url varchar(90) not null unique, cid integer not null references category(cid) );
input:
<?xml version="1.0" encoding="ISO-8859-1"?> <links xmlns:v="http://www.loisch.de/software/db2xml.html#v" xmlns:d="http://www.loisch.de/software/db2xml.html#d"> <!-- a view is like a function or a template --> <v:view id="category"> <category d:cid=""> <d:name/> <links> <!-- list all links in the current category --> <v:for-each> <v:query> SELECT lid as "_link__lid", url as "_link" FROM link WHERE cid = {$cid} </v:query> <v:row-values/> </v:for-each> </links> <!-- list all sub-categories by recursivly instantiating this view --> <categories> <v:for-each> <v:query>SELECT cid, name FROM category WHERE parent={$lcid}</v:query> <v:instantiate-view id="category"/> </v:for-each> </categories> </category> </v:view> <!-- initially select all categories that don't have a parent category --> <v:for-each> <v:query>SELECT cid, name FROM category WHERE parent IS NULL</v:query> <v:instantiate-view id="category"/> <v:for-each> </links>
output:
<?xml version="1.0" encoding="ISO-8859-1"?> <links> <category> <name>Root</name> <links> <link lid="1">http://www.loisch.de</link> <link lid="2">http://www.heise.de</link> </links> <categories> <category> <name>German universities</name> <links> <link lid="3">http://www.tum.de</link> <link lid="4">http://www.uni-freiburg.de</link> </link> <categories> <category> <name>Computer Science</name> <links> <link id="5">http://www.in.tum.de</link> </links> </category> </categories> </category> </categories> </category> </links>