I\'m writing a Java servlet in Eclipse (to be hosted on Google App Engine) and need to process an XML document. What libraries are available that are easy to add to an Eclip
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String content = req.getParameter("content");
Document doc = parseXml(content);
resp.setContentType("text/plain");
if (doc != null)
{
resp.getWriter().println(doc.getDocumentElement().getNodeName());
}
else
{
resp.getWriter().println("no input/bad xml input. please send parameter content=");
}
}
private static Document parseXml(String strXml)
{
Document doc = null;
String strError;
try
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
StringReader reader = new StringReader( strXml );
InputSource inputSource = new InputSource( reader );
doc = db.parse(inputSource);
return doc;
}
catch (IOException ioe)
{
strError = ioe.toString();
}
catch (ParserConfigurationException pce)
{
strError = pce.toString();
}
catch (SAXException se)
{
strError = se.toString();
}
catch (Exception e)
{
strError = e.toString();
}
log.severe("parseXml: " + strError);
return null;
}