xml.dom.minidom getElementsByTagName white space issue

Stefan Behnel stefan_ml at behnel.de
Fri Apr 10 01:58:30 EDT 2009


R. David Murray wrote:
> Leonardo lozanne wrote:
>> I'm getting some XML tags with white spaces from a web service and
>> when I try to get them with the getElements ByTagName I'm not able to
>> do so. I'm getting an empty list. What I'm doing is:
>> 
>> #XML_response is an xml string
>> xml_msg = xml.dom.minidom.parseString(XML_response)
>>  
>> nodes = xml_msg.getElementsByTagName("tag ten")  #tag name is "tag ten" with a whitespace
>>  
>> It all works fine with tags like tag_seven but NOT for tag names with
>> a white space. I've tried some escape chars but it doesnt seems to work.
>> 
>> Does anybody has the escape char sequence I should be using or a work
>> around for this? Thanks in advanced for your replies.
> 
> As far as I can tell what you are getting is invalid XML.
> So I think the answer is "you can't do that".
> 
> (cf: http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-NameChar)

Yes, that is correct. You should check why you are getting this (i.e. who
sends you this) and have them fix it. There is nothing you can (or should!)
do on your side to work around this.

Stefan



More information about the Python-list mailing list