You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
741 B
Java

String to Dom
package com.ack.xml.dom;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class StringToDom {
private static final String ADOC =
"<hello><name>john</name></hello>";
public static void main( String[] args ) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource( new StringReader( ADOC ) );
Document d = builder.parse( is );
}
catch( Exception ex ) {
ex.printStackTrace();
}
}
}