org.xml.sax.SAXParseException: Content is not allowed in prolog.在网上找了半天还是没解决。
dbconfig.xml<?xmlversion="1.0"encoding="UTF-8"?><config><dbinfo><driver-name>com.mysq...
dbconfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<dbinfo>
<driver-name>com.mysql.jdbc.Driver</driver-name>
<url>jdbc:mysql://127.0.0.1:3306/bbs</url>
<username>root</username>
<password>root</password>
</dbinfo>
</config>
import java.io.InputStream;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class Test {
public static void main(String[] args) {
try {
SAXReader saxReader = new SAXReader();
InputStream in = Test.class
.getResourceAsStream('/' + "dbconfig.xml");
System.out.println(in.read());
@SuppressWarnings("unused")
Document doc = saxReader.read(in);
//
Element driver = (Element) doc
.selectObject("/config/db-info/driver-name");
System.out.println(driver);
} catch (Exception e) {
e.printStackTrace();
}
}
}
这种从读取xml的方式,同学以前也试过,不知道为什么呢 展开
<?xml version="1.0" encoding="UTF-8"?>
<config>
<dbinfo>
<driver-name>com.mysql.jdbc.Driver</driver-name>
<url>jdbc:mysql://127.0.0.1:3306/bbs</url>
<username>root</username>
<password>root</password>
</dbinfo>
</config>
import java.io.InputStream;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class Test {
public static void main(String[] args) {
try {
SAXReader saxReader = new SAXReader();
InputStream in = Test.class
.getResourceAsStream('/' + "dbconfig.xml");
System.out.println(in.read());
@SuppressWarnings("unused")
Document doc = saxReader.read(in);
//
Element driver = (Element) doc
.selectObject("/config/db-info/driver-name");
System.out.println(driver);
} catch (Exception e) {
e.printStackTrace();
}
}
}
这种从读取xml的方式,同学以前也试过,不知道为什么呢 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询