String sFile = "Query.xml";
try {
DocumentBuilderFactory docbuilderfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docbuilder = docbuilderfactory.newDocumentBuilder();
doc = docbuilder.parse(sFile);
} catch (Exception e) {
System.out.println("Cannot read the command file: "+e.getMessage());
}
这是从一个文件中创建,如果想从一个字符串中创建,如:
String sXML="
1<query name="aaa">aaaa</query>
"
应该怎么做?
---------------------------------------------------------------
InputSource source = new InputSource (new StringReader (sXML));
doc = docbuilder.parse (source);