SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(new FileInputStream("exampleA.xml"));
我看大部分文档都是从文件生成DOC,然后处理
,如果我现在已经取得一个字符串,这个str1字符串是
str1="
<?xml version="1.0" encoding="GBK"?> <bookList> <book> <name>Java编程入门</name> <author>张三</author> <publishDate>2002-6-6</publishDate> <price>35.0</price> </book> <book> <name>XML在Java中的应用</name> <author>李四</author> <publishDate>2002-9-16</publishDate> <price>92.0</price> </book> </bookList>"那我应该怎么转成要处理的DOC?
Document doc = sb.build(new FileInputStream("exampleA.xml"));
我看大部分文档都是从文件生成DOC,然后处理
,如果我现在已经取得一个字符串,这个str1字符串是
str1="
<?xml version="1.0" encoding="GBK"?> <bookList> <book> <name>Java编程入门</name> <author>张三</author> <publishDate>2002-6-6</publishDate> <price>35.0</price> </book> <book> <name>XML在Java中的应用</name> <author>李四</author> <publishDate>2002-9-16</publishDate> <price>92.0</price> </book> </bookList>"那我应该怎么转成要处理的DOC?
doc = sb.build(in);
dbf.setNamespaceAware(true);
dbf.newDocumentBuilder().prase(new InputSource(new StringReader(xmlString)));
xmlString为xml的字符串