com.googlecode.gwt.test.internal.utils.GwtXMLParser Maven / Gradle / Ivy
package com.googlecode.gwt.test.internal.utils;
import com.google.gwt.dom.client.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import java.io.IOException;
import java.io.StringReader;
/**
* XML parser used by gwt-test-utils. It relies on the SAX API. For internal use
* only.
*
* @author Gael Lazzari
*/
public class GwtXMLParser {
private static XMLReader PARSER;
public static Document parse(String html) throws SAXException, IOException {
XMLReader saxReader = getParser();
GwtXmlContentHandler contentHandler = new GwtXmlContentHandler();
saxReader.setContentHandler(contentHandler);
saxReader.parse(new InputSource(new StringReader(html)));
return contentHandler.getParsedDocument();
}
private static XMLReader getParser() {
if (PARSER == null) {
PARSER = XmlUtils.newXMLReader();
}
return PARSER;
}
}