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]
# 1
Ha, the forums parsed my & l t;blah& g t; back into tag form :p
Zyphona at 2007-7-12 8:33:30 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 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

prgguya at 2007-7-12 8:33:30 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...