[XML-SIG] python+xml+sql
Oscar Luis Garcell Martinez
olgarcell at estudiantes.uci.cu
Tue May 27 00:23:01 CEST 2008
Hello everyone:
First of all i'm sorry by my bad english and sorry by the lenght of the message :D
I'm currently working in an aplication that parses the contains of a sql embebed inside an xml, with all the querys, transaction, etc, such as following:
<?xml version="1.0"?>
<sqlTransaction>
<selectQuery>
<tablesGroup>
<table name="usuarios" />
</tablesGroup>
<atributesGroup>
<atribute name="ausuario" column="usuario" table="usuarios" />
<atribute name="anombre" column="nombre" table="usuarios" />
<atribute name="apasswords" column="passwords"
table="usuarios" />
</atributesGroup>
<selectAtributes />
<valuesGroup>
<value name="vpasswords" data="1a2b" type="varchar" />
<value name="vname" data="Pepe" type="varchar" />
</valuesGroup>
<and>
<equalsThan nameLeft="passwords" nameRigth="vpasswords" />
<or>
<equalsThan nameLeft="anombre" nameRigth="vname" />
<equalsThan nameLeft="ausuario" nameRigth="vname" />
</or>
</and>
</selectQuery>
<selectQuery>
<tablesGroup>
<table name="usuarios" />
</tablesGroup>
<atributesGroup>
<atribute name="ausuario" column="usuario" table="usuarios" />
<atribute name="anombre" column="nombre" table="usuarios" />
<atribute name="apasswords" column="passwords"
table="usuarios" />
<atribute name="acargo" column="cargo" table="usuarios" />
</atributesGroup>
<selectAtributes>
<selected name="acargo" />
</selectAtributes>
<valuesGroup>
<value name="vpasswords" data="1a2b" type="varchar" />
<value name="vname" data="Pepe" type="varchar" />
</valuesGroup>
<and>
<equalsThan nameLeft="passwords" nameRigth="vpasswords" />
<or>
<equalsThan nameLeft="anombre" nameRigth="vname" />
<equalsThan nameLeft="ausuario" nameRigth="vname" />
</or>
</and>
</selectQuery>
<insertQuery>
<table name="usuarios" />
<atributesGroup>
<atribute name="ausuario" column="usuario" table="usuarios" />
<atribute name="anombre" column="nombre" table="usuarios" />
<atribute name="apasswords" column="passwords"
table="usuarios" />
<atribute name="acargo" column="cargo" table="usuarios" />
</atributesGroup>
<valuesGroup>
<value name="vusuario" data="Pepe" type="varchar" />
<value name="vname" data="Pepe" type="varchar" />
<value name="vpasswords" data="1a2b" type="varchar" />
<value name="vcargo" data="admin" type="varchar" />
</valuesGroup>
<asignGroup>
<asign nameLeft="ausuario" nameRigth="vusuario" />
<asign nameLeft="aname" nameRigth="vname" />
<asign nameLeft="apasswords" nameRigth="vpasswords" />
<asign nameLeft="acargo" nameRigth="vcargo" />
</asignGroup>
<and>
<equalsThan nameLeft="passwords" nameRigth="vpasswords" />
<or>
<equalsThan nameLeft="anombre" nameRigth="vname" />
<equalsThan nameLeft="ausuario" nameRigth="vname" />
</or>
</and>
</insertQuery>
<upDateQuery>
<table name="usuarios" />
<atributesGroup>
<atribute name="ausuario" column="usuario" table="usuarios" />
<atribute name="acargo" column="cargo" table="usuarios" />
</atributesGroup>
<valuesGroup>
<value name="vusuario" data="Pepe" type="varchar" />
<value name="vcargo" data="admin" type="varchar" />
</valuesGroup>
<asignGroup>
<asign nameLeft="acargo" nameRigth="vcargo" />
</asignGroup>
<equalsThan nameLeft="ausuario" nameRigth="vusuario" />
</upDateQuery>
<deleteQuery>
<table name="usuarios" />
<atributesGroup>
<atribute name="acargo" column="cargo" table="usuarios" />
</atributesGroup>
<valuesGroup>
<value name="vcargo" data="nodeseado" type="varchar" />
</valuesGroup>
<equalsThan nameLeft="acargo" nameRigth="vcargo" />
</deleteQuery>
</sqlTransaction>
that will be an select query that would be applied to some database (i'm working under postgresql), the UI of my aplication was made by myself using qt-4.4.0 (always python2.5) and i have some question cause I had spend only a few moths learning python+xml , today i have the 75 % of the functionality completed, but i need know how access to the attributes of the xml, example, this is my output:
-------- Inicio documento --------
Elemento: sqlTransaction
Elemento: selectQuery
Elemento: tablesGroup
Elemento: table
Atributo -- Name: name Value: usuarios
Elemento: atributesGroup
Elemento: atribute
Atributo -- Name: column Value: usuario
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: ausuario
Elemento: atribute
Atributo -- Name: column Value: nombre
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: anombre
Elemento: atribute
Atributo -- Name: column Value: passwords
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: apasswords
Elemento: selectAtributes
Elemento: valuesGroup
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: 1a2b
Atributo -- Name: name Value: vpasswords
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: Pepe
Atributo -- Name: name Value: vname
Elemento: and
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vpasswords
Atributo -- Name: nameLeft Value: passwords
Elemento: or
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vname
Atributo -- Name: nameLeft Value: anombre
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vname
Atributo -- Name: nameLeft Value: ausuario
Elemento: selectQuery
Elemento: tablesGroup
Elemento: table
Atributo -- Name: name Value: usuarios
Elemento: atributesGroup
Elemento: atribute
Atributo -- Name: column Value: usuario
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: ausuario
Elemento: atribute
Atributo -- Name: column Value: nombre
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: anombre
Elemento: atribute
Atributo -- Name: column Value: passwords
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: apasswords
Elemento: atribute
Atributo -- Name: column Value: cargo
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: acargo
Elemento: selectAtributes
Elemento: selected
Atributo -- Name: name Value: acargo
Elemento: valuesGroup
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: 1a2b
Atributo -- Name: name Value: vpasswords
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: Pepe
Atributo -- Name: name Value: vname
Elemento: and
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vpasswords
Atributo -- Name: nameLeft Value: passwords
Elemento: or
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vname
Atributo -- Name: nameLeft Value: anombre
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vname
Atributo -- Name: nameLeft Value: ausuario
Elemento: insertQuery
Elemento: table
Atributo -- Name: name Value: usuarios
Elemento: atributesGroup
Elemento: atribute
Atributo -- Name: column Value: usuario
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: ausuario
Elemento: atribute
Atributo -- Name: column Value: nombre
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: anombre
Elemento: atribute
Atributo -- Name: column Value: passwords
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: apasswords
Elemento: atribute
Atributo -- Name: column Value: cargo
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: acargo
Elemento: valuesGroup
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: Pepe
Atributo -- Name: name Value: vusuario
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: Pepe
Atributo -- Name: name Value: vname
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: 1a2b
Atributo -- Name: name Value: vpasswords
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: admin
Atributo -- Name: name Value: vcargo
Elemento: asignGroup
Elemento: asign
Atributo -- Name: nameRigth Value: vusuario
Atributo -- Name: nameLeft Value: ausuario
Elemento: asign
Atributo -- Name: nameRigth Value: vname
Atributo -- Name: nameLeft Value: aname
Elemento: asign
Atributo -- Name: nameRigth Value: vpasswords
Atributo -- Name: nameLeft Value: apasswords
Elemento: asign
Atributo -- Name: nameRigth Value: vcargo
Atributo -- Name: nameLeft Value: acargo
Elemento: and
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vpasswords
Atributo -- Name: nameLeft Value: passwords
Elemento: or
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vname
Atributo -- Name: nameLeft Value: anombre
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vname
Atributo -- Name: nameLeft Value: ausuario
Elemento: upDateQuery
Elemento: table
Atributo -- Name: name Value: usuarios
Elemento: atributesGroup
Elemento: atribute
Atributo -- Name: column Value: usuario
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: ausuario
Elemento: atribute
Atributo -- Name: column Value: cargo
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: acargo
Elemento: valuesGroup
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: Pepe
Atributo -- Name: name Value: vusuario
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: admin
Atributo -- Name: name Value: vcargo
Elemento: asignGroup
Elemento: asign
Atributo -- Name: nameRigth Value: vcargo
Atributo -- Name: nameLeft Value: acargo
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vusuario
Atributo -- Name: nameLeft Value: ausuario
Elemento: deleteQuery
Elemento: table
Atributo -- Name: name Value: usuarios
Elemento: atributesGroup
Elemento: atribute
Atributo -- Name: column Value: cargo
Atributo -- Name: table Value: usuarios
Atributo -- Name: name Value: acargo
Elemento: valuesGroup
Elemento: value
Atributo -- Name: type Value: varchar
Atributo -- Name: data Value: nodeseado
Atributo -- Name: name Value: vcargo
Elemento: equalsThan
Atributo -- Name: nameRigth Value: vcargo
Atributo -- Name: nameLeft Value: acargo
-------- Final documento --------
Elemento means element and Atributo means attribute.
I'm using the SAX library, and obviusly, is very simple use it, Now this is my question:
How can i get a well formed output, i means something like this:
Select * from [usuarios] where = ([usuarios].[passwords] = ¨1a2b¨) AND ([usuarios].[usuario]
= ¨Pepe¨ OR [usuarios]. [nombre] = ¨Pepe¨)
I'm a student, currently 3rd year of Informatics Sciences and i will appreciate any help that you could bring me.
Thanks
Linux User# 422193
KDE User # 2794
More information about the XML-SIG
mailing list