tags:

views:

249

answers:

3

I'm looking for an XML editor that lets me type and copy and paste arbitrary text into an XML element or attribute without requiring me to go back through and escape any characters that must use reserved XML entities (ampersands, angle brackets, or quote marks). XMLSpy came up short.

A: 

You could use Notepad++ and the TextFX plugin for it.

Notepad++ is a decent free programmer's editor that does XML. Add the TextFX plugin and you will get a menu item TextFX | Encode HTML.

Rob Prouse
That's a nice text editor, but selecting text and choosing "encode HTML" is a little cumbersome and raises the possibility of overescaping.
+2  A: 

Do you really expect the editor to know that when you paste a<b it should escape the < , but when you paste a<b/> it shouldn't? Seems like a tall order...

Having thought about this for a bit, I think that what you want can be achieved, either through a separate "Special Paste" command, or a special editor mode.

A Google search reveals that ExchangerXML seems to offer the desired paste behavior.

Another option might be a programmable text or XML editor which can let you define a "macro" for "Paste text and post-process it with the following string substitutions" (or, alternatively, "perform substitutions on the text in clipboard, then paste"). I'll bet emacs can do it, but I'm not an emacs user.

Alternatively, you might consider using CDATA sections and pasting your text unescaped inside those instead. This will work in any editor:

<![CDATA[a<b]]>
ykaganovich
If I'm pasting "a<b/>" into an XML element or attribute as text, I would expect the XML editor to escape the "<" and ">".
If you say so, but for me it would be completely unacceptable inside the element.
ykaganovich
Why? If an element contains text, why should the text not be allowed to contain escaped angle brackets?
I tried ExchangerXML, but it didn't work. When I type in an ampersand in the Grid Editor and then switch to the Text Editor, the ampersand isn't escaped. Then I can't switch back to the grid editor which I was just in because the XML isn't well-formed.
+1  A: 

I just realized I have Visual Studio 2005 and it has the behavior I'm looking for.