Hello everyone. I'm Alessio Esposito and collaborate with the Institute of Cybernetics of the CNR in Pozzuoli (NA) - Italy, I have the latest version of lxml (lxml 2.1.4). I need to have something like this: ... <octapyelement xsi:schemaLocation="http://octapycms.remuna.org/schema.xsd"> <octapy:first> something </octapy:first> <octapy:second> something </octapy:second> ... ... </octapyelement> ... And this is the python code: ... e_octapy = SubElement(rootelement, 'octapyelement') e_octapy.set('{%s}schemaLocation' % NS_XSI, 'http://octapycms.remuna.org/schema.xsd') for sub_elem in struct: e = SubElement( e_octapy, sub_elem ) e.text = 'something' ... The variable sub_elem contain strings octapy:first, octapy:second etc. The problem is that the latest version of lxml does not accept that sub_elem contains ':' . This is a part of the terminal output: Module lxml.etree, line 2342, in lxml.etree.SubElement (src/lxml/lxml.etree.c:%u) Module lxml.etree, line 160, in lxml.etree._makeSubElement (src/lxml/lxml.etree.c:%u) Module lxml.etree, line 1311, in lxml.etree._tagValidOrRaise (src/lxml/lxml.etree.c:%u) ValueError: Invalid tag name u'octapy:first' The previous version of lxml (lxml 2.1) whit the same code gave no problems. How can I fix this? Kind regards, Alessio. -- Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it: http://www.email.it/f Sponsor: CheBanca! La prima banca che ti dà gli interessi in anticipo. Fino al 4,70% sul Conto Deposito, zero spese e interessi subito. Aprilo! Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=8435&d=20081215
[replying to all...] pythonalex@email.it wrote:
e = SubElement( e_octapy, sub_elem )
The problem is that the latest version of lxml does not accept that sub_elem contains ':' .
You have to provide the namespace URI instead of the prefix. http://codespeak.net/lxml/tutorial.html#namespaces
The previous version of lxml (lxml 2.1) whit the same code gave no problems.
I doubt that. Tag validation has been in there for a while. Stefan
Thank you for the rapidity of the response, I will follow your indications. On the question of the version I can guarantee you that before there were no problems. Thanks Again, Alessio.
participants (3)
-
Alessio Esposito -
pythonalex@email.it -
Stefan Behnel