How to Parse a string into an XML DOM ?

Hi,I want to parse a String into an XML DOM. Not able to locate any parser which supports that. Any pointers to this?
[131 byte] By [Amit.Sriva] at [2007-11-26 21:44:43]
# 1

Download Xerces from xml.apache.org. Place the relevant JAR's on your classpath. Here is sample code to get a DOM document reference.

- Saish

public final class DomParser extends Object {

/////////////////////

// Class Variables //

/////////////////////

private static final DocumentBuilder builder;

private static final String JAXP_SCHEMA_LANGUAGE =

"http://java.sun.com/xml/jaxp/properties/schemaLanguage";

/** W3C schema definitions */

private static final String W3C_XML_SCHEMA =

"http://www.w3.org/2001/XMLSchema";

//////////////////

// Constructors //

//////////////////

static {

try {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setNamespaceAware(true);

factory.setValidating(true);

factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);

builder = factory.newDocumentBuilder();

builder.setErrorHandler(new ErrorHandler() {

public void warning(SAXParseException e) throws SAXException {

System.err.println("[warning] "+e.getMessage());

}

public void error(SAXParseException e) throws SAXException {

System.err.println("[error] "+e.getMessage());

}

public void fatalError(SAXParseException e) throws SAXException {

System.err.println("[fatal error] "+e.getMessage());

throw new XmlParsingError("Fatal validation error", e);

}

});

}

catch (ParserConfigurationException fatal) {

throw new ConfigurationError("Unable to create XML DOM document parser", fatal);

}

catch (FactoryConfigurationError fatal) {

throw new ConfigurationError("Unable to create XML DOM document factory", fatal);

}

}

private DomParser() {

super();

}

////////////////////

// Public Methods //

////////////////////

public static final Document newDocument() {

return builder.newDocument();

}

public static final Document parseDocument(final InputStream in) {

try {

return builder.parse(in);

}

catch (SAXException e) {

throw new XmlParsingError("SAX exception during parsing. Document is not well-formed or contains " +

"illegal characters", e);

}

catch (IOException e) {

throw new XmlParsingError("Encountered I/O exception during parsing", e);

}

}

}

- Saish

Saisha at 2007-7-10 3:32:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Any JAXP-compliant parser will do this, including the one you already have if you are using Java 1.4 or later.parse(new InputSource(new StringReader(someString)))
DrClapa at 2007-7-10 3:32:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
Hi...Thanks for the response. It did work !
Amit.Sriva at 2007-7-10 3:32:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...