xml.sax removing newlines from attribute value?

Discussion in 'Python' started by Grant Edwards, Sep 29, 2005.

  1. I'm using xml.sax to parse the "datebook" xml file generated by
    QTopiaDesktop. When I look at the xml file, some of the
    attribute strings have newlines in them (as they are supposed

    However, when xml.sax passes the attributes to my
    startElement() method the newlines seem to have been deleted.

    How do I get the un-munged element attribute values?
    Grant Edwards, Sep 29, 2005
    1. Advertisements

  2. newlines as in chr(10) rather than

    if so, the only way is to avoid XML:


    if the "yes, I know, but I have good reasons" approach is okay with you,
    and you're big enough to defend yourself against the XML-Is-The-Law
    crowd, you can use a "sloppy" XML parsers such as sgmlop to deal with
    your files:


    Fredrik Lundh, Sep 29, 2005
    1. Advertisements

  3. Yup, Looks that way.
    I can't quite find it in the BNF, but I take it that chr(10)
    isn't really allowed in XML attribute strings. IOW, the file
    generate by Trolltech's app is broken.
    I didn't define the file or write the program that generated
    it. It's claimed to be "xml", and I'm just trying to parse it.
    Good to know for future reference. For now, I think I'll just
    live with the way it works. Everything basically works, except
    some strings don't display quite "right". My current app
    treats the file as read-only. If I ever get around to
    modifying data and writing it back, I'll probably have to deal
    with the newline issue at that point.
    Grant Edwards, Sep 29, 2005
  4. it's allowed, but the parser must not pass it on to the application.

    (in other words, whitespace in attributes doesn't, in general, survive

    Fredrik Lundh, Sep 29, 2005
  5. Ah, I see. That's good to know.

    [This is my first attempt at anything XMLish.]
    Grant Edwards, Sep 29, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.