xml.dom.minidom getElementsByTagName white space issue

Discussion in 'Python' started by R. David Murray, Apr 9, 2009.

  1. Leonardo lozanne <> wrote:
    > Hi,
    >  
    > 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)

    --
    R. David Murray http://www.bitdance.com
     
    R. David Murray, Apr 9, 2009
    #1
    1. Advertising

  2. 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
     
    Stefan Behnel, Apr 10, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Wogan-Browne
    Replies:
    1
    Views:
    832
    Uche Ogbuji
    Jan 28, 2005
  2. Ben C
    Replies:
    6
    Views:
    2,187
    Leif K-Brooks
    Jan 28, 2007
  3. Replies:
    3
    Views:
    548
    Stefan Behnel
    Aug 3, 2007
  4. Johannes Bauer
    Replies:
    7
    Views:
    1,076
    Johannes Bauer
    Jun 11, 2009
  5. ming
    Replies:
    2
    Views:
    187
Loading...

Share This Page