Escaping XML Special Characters
Are there any ways built into the Java API to escape XML special characters, i.e. <blah> => <blah>? I'm trying to throw a user inputed String into my XML tree, but I, of course, will get problems if they start inputting >, <, ', ", or other special characters.
Thanks,
Andy
[315 byte] By [
Zyphona] at [2007-11-27 3:30:28]

# 2
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
String str = <your string>;
StringReader reader = new StringReader(str);
Document doc = parser.parse(new InputSource(reader));
It's worth taking a look at this too:
http://forum.java.sun.com/thread.jspa?threadID=5147742&messageID=9551277