From olgarcell at estudiantes.uci.cu Tue May 27 00:23:01 2008 From: olgarcell at estudiantes.uci.cu (Oscar Luis Garcell Martinez) Date: Mon, 26 May 2008 18:23:01 -0400 Subject: [XML-SIG] python+xml+sql Message-ID: 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:
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 From bortzmeyer at nic.fr Thu May 29 14:21:04 2008 From: bortzmeyer at nic.fr (Stephane Bortzmeyer) Date: Thu, 29 May 2008 14:21:04 +0200 Subject: [XML-SIG] python+xml+sql In-Reply-To: References: Message-ID: <20080529122104.GA13313@nic.fr> On Mon, May 26, 2008 at 06:23:01PM -0400, Oscar Luis Garcell Martinez wrote a message of 361 lines which said: > How can i get a well formed output, i means something like this: > > Select * from [usuarios] This is certainly not well-formed SQL. > where = ([usuarios].[passwords] = ?1a2b?) AND ([usuarios].[usuario] > = ?Pepe? OR [usuarios]. [nombre] = ?Pepe?) The obvious, but wrong, solution, is to use print(). The reason why it is wrong and what you should do is well explained in the attached message. -------------- next part -------------- An embedded message was scrubbed... From: Chris Cogdon Subject: Re: am I doing something wrong or is this a bug Date: Thu, 10 Jan 2008 21:03:34 -0800 Size: 5418 URL: From iwan at reahl.org Fri May 30 16:44:31 2008 From: iwan at reahl.org (Iwan Vosloo) Date: Fri, 30 May 2008 16:44:31 +0200 Subject: [XML-SIG] Alternatives for xml.dom.ext.reader.HtmlReader? Message-ID: <1212158671.12355.47.camel@easymoney> Hi there, We have code using PyXML modules xml.dom.ext.reader.HtmlReader and xml.dom.ext.Print After an upgrade from ubuntu gutsy to hardy, this now breaks, because the hardy release moved python-xml from the default path (see https://bugs.launchpad.net/ubuntu/+source/python-xml/+bug/215723 ) We have tried the workaround suggested in the changelog, which is to do: sys.path.append('/usr/lib/python%s/site-packages/oldxml' % sys.version[:3]) But, that has to be done before the first xml import, and determining the first xml import is a bit difficult in a large app... We're using these to solve the following problem: - to read possibly erroneous HTML (not XML) into a dom tree - and then to create an html fragment (part of the complete doc) which we have to render as a chunk of HTML (not XML) again. We decided on using these, based on http://www.boddie.org.uk/python/HTML.html . We don't really want to use libxml2dom as also suggested there, since it is not packaged for ubuntu (and dealing with ad-hoc unpackaged things would be a nightmare in our environment). We also tried the following at the start of the problematic module: import sys import test.test_support test.test_support.forget('xml') test.test_support.forget('xml.dom') sys.path.insert(0,'/usr/lib/python%s/site-packages/oldxml' % sys.version[:3]) But this also does not work... Any pointers to a quick workaround would be appreciated. (And to "the right way" too) Thanks -i From stefan_ml at behnel.de Fri May 30 22:40:34 2008 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 30 May 2008 22:40:34 +0200 Subject: [XML-SIG] Alternatives for xml.dom.ext.reader.HtmlReader? In-Reply-To: <1212158671.12355.47.camel@easymoney> References: <1212158671.12355.47.camel@easymoney> Message-ID: <48406642.9030603@behnel.de> Iwan Vosloo wrote: > We don't really want to use libxml2dom as also suggested there, since it > is not packaged for ubuntu (and dealing with ad-hoc unpackaged things > would be a nightmare in our environment). Try lxml, it's packaged in Ubuntu. However, for HTML, you might want to use lxml.html, which is an enhanced tool set for HTML handling that comes with lxml 2.0. That's not currently in Ubuntu, but it's in Debian (and it's also trivial to install with easy_install in Ubuntu). http://codespeak.net/lxml Stefan