How to parse xml with ISO-8859-1 encoding using ElementTree and SimpleXMLTreeBuilder?

2008-05-13 Thread Zvi
Hi All,

I got trouble parsing xml returned by web service. XML data contains
characters above 128, so ET.fromstring throws an error. Error is
thrown from python's xmllib.py file, where it detects char above 128.
I am replacing utf-8 encoding string in returned xml with
'ISO-8859-1', and then I call .encode with ISO-8859-1 param. Still I
get the parsing error, illegal character.
What's interesting is that if I define a string const and assign it
the value returned from the service request it gets parsed. I.e. the
following gets parsed ok.


TEST_EVNVELOPE2 = """
 http://www.w3.org/2001/
XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
 
 
 """

CHARSET = 'ISO-8859-1'

  ET.XMLTreeBuilder = SimpleXMLTreeBuilder.TreeBuilder
  spEnv = TEST_EVNVELOPE2
  spEnv = spEnv.replace('utf-16', CHARSET)
  spEnv = spEnv.replace('utf-8', CHARSET)
  dom=ET.fromstring(spEnv.encode(CHARSET))

however when spEnv is assigned response.content directly I get parsing
error in ET.fromstring, even though TEST_EVNVELOPE2 value is just
pasted from the browser's src code, that is I just dumped
response.content to rendered html and then copied it from html src.
Why it works as a  string const and not as variable value?

So, what's the correct way to make parsing work?

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


Problem parsing SOAP envelope with ElementTree

2008-05-06 Thread Zvi
Hi All,

   Can someone tell me why id the following not working?
I have a soap response envelope, for test purpose it's just a string
and I create ElementTree from it.
Then I try to find Response tag, but I get None.


   data = """http://schemas.xmlsoap.org/
soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
   
 
  """

   ElementTree.XMLTreeBuilder = SimpleXMLTreeBuilder.TreeBuilder
   dom=ElementTree.fromstring(data)

   if dom == None:
 return "Empty Dom"

   response = dom.find('{http://schemas.xmlsoap.org/soap/
envelope/}Response')
   if response == None:
 return "Empty Response"

   if I try to use
response = dom.find('{http://tempuri.org/}Response') this doesn't work
either.

What am I doing wrong?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem parsing SOAP envelope with ElementTree

2008-05-07 Thread Zvi
On May 7, 1:12 am, Waldemar Osuch <[EMAIL PROTECTED]> wrote:
Thanks a lot :)
P.S. It was a complete code, I didn't write anything else.
--
http://mail.python.org/mailman/listinfo/python-list