*argh!*  I hate XML!   There, now that that's off my chest...

I am trying to save Python code as attributes of an XML tag with
xml.dom.minidom machinery.  The code, predicatbly enough, contains newlines.
If I do nothing to my program text, upon output I get XML which looks like
this:

    <SomeTag text="def _f():
    return 3
"/>

When that is later parsed, the newlines are replaced by spaces.  That's
clearly no good.

I verified manually that if I changed the above to

    <SomeTag text="def _f():&#10;    return 3&#10;"/>

when read in, the entities are replaced by newlines and the function is
restored to its normal indented, multiline self.  "No problem," I thought,
just update the call the setAttribute() on the node:

    node.setAttribute(key, str(val).replace("\n", "&#10;"))

Alas, that leaves me with this tag:

    <SomeTag text="def _f():&amp;#10;    return 3&amp;#10;"/>

which doesn't work for obvious reasons.

Is there a way to achieve XML attribute newline nirvana?  Please show me the
path to enlightenment.

Thx,

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

Reply via email to