Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54396
| Date | 2013-09-18 22:35 +0300 |
|---|---|
| From | Burak Arslan <burak.arslan@arskom.com.tr> |
| Subject | Re: lxml question -- creating an etree.Element attribute with ':' in the name |
| References | <F1EF559F-76E7-42F4-AC96-5EC0E8B6DBA1@panix.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.131.1379532913.18130.python-list@python.org> (permalink) |
On 09/18/13 21:59, Roy Smith wrote:
> I can create an Element with a 'foo' attribute by doing:
>
> etree.Element('my_node_name', foo="spam")
>
> But, how do I handle something like:
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance", since "xmlns:xsi" isn't a valid python identifier?
>
>
xmlns: is a prefix with a special meaning: it defines an xml namespaces
prefix. you should read about how they work.
The following:
Element('{http://www.w3.org/2001/XMLSchema-instance}my_node_name')
will generate a proper xmlns declaration for you. It may not be the same
every time, but it will do the job just as well.
btw, if you need to generate xml schemas, have a look at spyne:
http://spyne.io
Specifically:
https://github.com/arskom/spyne/blob/master/examples/xml/schema.py
best,
burak
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: lxml question -- creating an etree.Element attribute with ':' in the name Burak Arslan <burak.arslan@arskom.com.tr> - 2013-09-18 22:35 +0300
csiph-web