I am trying to create a patch to Inkscape and it isn't working very well, I was hoping I could ask for some help.

I have been using Inkscape for creating resources for a video game I'm writing. As part of this I often attach custom attributes to XML nodes in the "XML Editor" window. When I do this, Inkscape gives me a nice big multiline editor window to enter my attribute text. Sometimes, I find myself needing to enter many lines of text or code into one of my custom attributes; when I do this, Inkscape handles newlines in a way that strikes me as incorrect and makes it very hard for me to get work done. Inkscape will allow me to enter, set and save multi-line attributes; however then later when I try to open the file, all the newlines will be erased, replaced with spaces. Although I understand newlines are rarely relevant in normal SVG, it seems very wrong to me that Inkscape allows me to enter content, save a file, and then reopen the file and it has been silently altered.

I have been trying to fix this behavior on my own. What I found is that if you put a newline into an attribute and then save, Inkscape will actually write the newline raw into the file, like--
<example:example attribute="one two
three four" />
When the file is opened the next time, Inkscape silently turns all newlines into spaces.

The convert-newline-to-space behavior is apparently not only correct, but required for a conformant XML parser:
http://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize
So my conclusion is that if Inkscape is doing something wrong here (which I think it is), the mistake is that it should not be writing newlines raw into the file, rather it should be saving the appropriate XML entity (&#10; or &#xA;).

I have a local branch (patch attached) where I have attempted to implement this change. I can't get it to work. I found four separate places in the source code where strings are escaped into XML entities for storage; I added a '\n' -> &#xA; rule to each, and taught xmlreader.cpp to convert &#xA; back into '\n'. The reader change seems to have worked (I can manually write a &#xA into a file, and when loaded in Inkscape it becomes a newline) however, when I write a newline into an attribute and then set and save, Inkscape is still writing raw newlines instead of my escaped attribute.

While making this change, I noticed two things that seem problematic:

- XML entity escaping is done in at least four separate places in the code!
- The XML reader in dom/xmlreader.cpp appears to only recognize a small number of hand-entered entities. At the moment there is no provision for loading any kind of &# style entity, which if I'm not missing something means Inkscape could choke on valid SVG XML produced by a different program.

Should either of these two things be fixed?

And would anyone know why my attempts to add '\n' to the escaper are having no effect? When you enter text into the attribute-value box in the XML editor, what path does it take in being entity-escaped (i.e. " becomes &quot; and so on)?

One more question-- other than this one problem the XML editor in Inkscape is quite nice, are there any examples of standalone programs for Mac or Linux that allow you to edit general XML in this manner?

Thanks.

- mcc
http://runhello.com/