Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attribute': 0.07; 'element': 0.07; 'subject: -- ': 0.07; 'defines': 0.09; 'prefix': 0.09; 'url:github': 0.09; 'subject:question': 0.10; 'cc:addr :python-list': 0.11; 'python': 0.11; 'burak': 0.16; 'cc:name:python list': 0.16; 'declaration': 0.16; 'doing:': 0.16; 'from:addr:arskom.com.tr': 0.16; 'from:addr:burak.arslan': 0.16; 'from:name:burak arslan': 0.16; 'message-id:@arskom.com.tr': 0.16; 'received:arskomhosting.com': 0.16; 'roy': 0.16; 'subject:skip:e 10': 0.16; 'url:py': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'xml': 0.29; 'work.': 0.31; 'subject:the': 0.34; 'subject:with': 0.35; 'something': 0.35; 'but': 0.35; 'url:org': 0.36; 'should': 0.36; 'handle': 0.38; 'skip:x 10': 0.40; 'how': 0.40; 'read': 0.60; 'you.': 0.62; 'smith': 0.68; 'special': 0.74; "'foo'": 0.84; 'url:master': 0.84 Date: Wed, 18 Sep 2013 22:35:10 +0300 From: Burak Arslan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130711 Thunderbird/17.0.7 MIME-Version: 1.0 To: Roy Smith Subject: Re: lxml question -- creating an etree.Element attribute with ':' in the name References: In-Reply-To: X-Enigmail-Version: 1.5.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379532913 news.xs4all.nl 15990 [2001:888:2000:d::a6]:53760 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54396 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