XML Processing

J

Jay Loden

Robert said:
Both strings in your example are exactly the same, unless I'm missing
something.


Robert, your newsreader/mail program is converting the HTML/XML entity codes into the corresponding character so you're not seeing the plain text version of what the OP posted. He's asking for code to convert XML entities like '&' into their escaped strings.

I believe xml.sax.saxutils.encode() is what the OP is looking for:
'http://myhome/&param'

-Jay
 
J

Jay Loden

I've seen examples using the HTMLgen module. But here's another script
I just found:

http://mail.python.org/pipermail/python-list/1999-November/016814.html

I would think that you could use regular expressions too.

Mike

I would reccommend against using the example above or using regular expressions, since both are likely to miss corner cases, and the stdlib has an encode function that's already designed for this task

http://docs.python.org/lib/module-xml.sax.saxutils.html

The encode() function in xml.sax.saxutils also is extensible, should you run into any entities that it fails to escape in the current implementation.

-Jay
 
K

kyosohma

I would reccommend against using the example above or using regular expressions, since both are likely to miss corner cases, and the stdlib has an encode function that's already designed for this task

http://docs.python.org/lib/module-xml.sax.saxutils.html

The encode() function in xml.sax.saxutils also is extensible, should you run into any entities that it fails to escape in the current implementation.

-Jay

Yes, I am an idiot.
 
C

Cameron Laird

expressions, since both are likely to miss corner cases, and the stdlib
has an encode function that's already designed for this task
you run into any entities that it fails to escape in the current
implementation.

Yes, I am an idiot.

! Unproved, as Scotsmen are wont to say.

This and similar questions arise frequently enough that I recommend
<URL: http://wiki.python.org/moin/EscapingXml > for those who want
to pursue the subject.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top