Re: lxml question -- creating an etree.Element attribute with ':' in the name

2019-12-03 Thread Karsten Hilbert
On Mon, Dec 02, 2019 at 08:58:11PM -0800, gerem...@gmail.com wrote:
> Date: Mon, 2 Dec 2019 20:58:11 -0800 (PST)
> From: gerem...@gmail.com
> To: python-list@python.org
> Subject: Re: lxml question -- creating an etree.Element attribute with ':'
>  in the name
> User-Agent: G2/1.0
>
> Theanks a lot
> --
> https://mail.python.org/mailman/listinfo/python-list

you are welcoem

--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: lxml question -- creating an etree.Element attribute with ':' in the name

2019-12-03 Thread geremy85
Theanks a lot
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: lxml question -- creating an etree.Element attribute with ':' in the name

2013-09-19 Thread dieter
Roy Smith r...@panix.com writes:

 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?

Read about lxml's namespace support.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: lxml question -- creating an etree.Element attribute with ':' in the name

2013-09-19 Thread Stefan Behnel
Burak Arslan, 18.09.2013 21:35:
 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.

Absolutely. For the specific case of a namespaced attribute, one way to do
it goes like this:

   el = etree.Element('my_node_name')
   el.set('{http://www.w3.org/2001/XMLSchema-instance}xsi', 'int')


 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.

For this specific namespace, and also a couple of other well-known
namespace URIs, lxml will use the expected prefix by default.

Stefan


-- 
https://mail.python.org/mailman/listinfo/python-list


lxml question -- creating an etree.Element attribute with ':' in the name

2013-09-18 Thread Roy Smith
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?

---
Roy Smith
r...@panix.com



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: lxml question -- creating an etree.Element attribute with ':' in the name

2013-09-18 Thread Zachary Ware
On Wed, Sep 18, 2013 at 1:59 PM, Roy Smith r...@panix.com 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?


Try this:

etree.Element('my_node_with_invalid_identifiers_name', **{'xmlns:xsi': 'spam'})

HTH,

-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: lxml question -- creating an etree.Element attribute with ':' in the name

2013-09-18 Thread Burak Arslan
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: lxml question

2009-09-10 Thread Diez B. Roggisch
mattia wrote:

 I would like to click on an image in a web page that I retrieve using
 urllib in order to trigger an event.
 Here is the piece of code with the image that I want to click:
 input type=image style=border-width: 0px; height: 22px; width: 49px;
 onclick=return checkPhoneField(document.contactFrm, 'mobile');
 alt=sms src=images/button_sms.bmp id=smsToMobile name=smsToMobile/

 
 I don't know how to do it (I'm trying using lxml, but any suggestion can
 help).

Install something like HTTP-live-headers or Firebug and analyze what the
actual HTTP-requests are. Then model these.


Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


lxml question

2009-09-09 Thread mattia
I would like to click on an image in a web page that I retrieve using 
urllib in order to trigger an event. 
Here is the piece of code with the image that I want to click:
input type=image style=border-width: 0px; height: 22px; width: 49px; 
onclick=return checkPhoneField(document.contactFrm, 'mobile'); 
alt=sms src=images/button_sms.bmp id=smsToMobile name=smsToMobile/


I don't know how to do it (I'm trying using lxml, but any suggestion can 
help).

Thanks, 
Mattia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lxml question

2009-09-09 Thread Chris Rebert
On Wed, Sep 9, 2009 at 4:11 PM, mattiager...@gmail.com wrote:
 I would like to click on an image in a web page that I retrieve using
 urllib in order to trigger an event.
 Here is the piece of code with the image that I want to click:
 input type=image style=border-width: 0px; height: 22px; width: 49px;
 onclick=return checkPhoneField(document.contactFrm, 'mobile');
 alt=sms src=images/button_sms.bmp id=smsToMobile name=smsToMobile/


 I don't know how to do it (I'm trying using lxml, but any suggestion can
 help).

You need to hook into an actual web browser since the event is JavaScript code.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lxml question

2008-10-03 Thread Stefan Behnel
Uwe Schmitt wrote:
 I have to parse some text which pretends to be XML. lxml does not want
 to parse it, because it lacks a root element.
 I think that this situation is not unusual, so: is there a way to
 force lxml to parse it ?
 
 My work around is wrapping the text with root.../root before
 feeding lxmls parser.

Yes, you can do that. To avoid creating an intermediate string, you can use
the feed parser and do something like this:

parser = etree.XMLParser()
parser.feed(root)
parser.feed(your_xml_tag_sequence_data)
parser.feed(/root)
root = parser.close()

Stefan
--
http://mail.python.org/mailman/listinfo/python-list


lxml question

2008-09-26 Thread Uwe Schmitt
Hi,

I have to parse some text which pretends to be XML. lxml does not want
to parse it, because it lacks a root element.
I think that this situation is not unusual, so: is there a way to
force lxml to parse it ?

My work around is wrapping the text with root.../root before
feeding lxmls parser.

Greetings, Uwe
--
http://mail.python.org/mailman/listinfo/python-list


Re: lxml question

2008-09-26 Thread Mark Thomas
On Sep 26, 11:19 am, Uwe Schmitt [EMAIL PROTECTED]
wrote:
 I have to parse some text which pretends to be XML. lxml does not want
 to parse it, because it lacks a root element.
 I think that this situation is not unusual, so: is there a way to
 force lxml to parse it ?

By pretends to be XML you mean XML-like but not really XML?

 My work around is wrapping the text with root.../root before
 feeding lxmls parser.

That's actually not a bad solution, if you know that the document is
otherwise well-formed. Another thing you can do is use libxml2's
recover mode which accommodates non-well-formed XML.

parser = etree.XMLParser(recover=True)
tree = etree.XML(your_xml_string, parser)

You'll still need to use your wrapper root element, because recover
mode will ignore everything after the first root closes (and it won't
throw an error).

-- Mark.
--
http://mail.python.org/mailman/listinfo/python-list


Re: lxml question

2008-09-26 Thread alex23
On Sep 27, 1:19 am, Uwe Schmitt [EMAIL PROTECTED]
wrote:
 I have to parse some text which pretends to be XML. lxml does not want
 to parse it, because it lacks a root element.

Another option is BeautifulSoup, which handles badly formed XML really
well:

http://www.crummy.com/software/BeautifulSoup/
--
http://mail.python.org/mailman/listinfo/python-list