举例说明比较容易
一,对于以DTD为Schema的XML文件
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">publicId是-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN
SystemId是http://java.sun.com/dtd/web-app_2_3.dtd二,对于以xsd为Schema的XML文件
<syn:address xmlns:syn="http://www.xxxxxx.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.xxxxxx.com/ http://www. xxxxxx.com/address.xsd">publicId是?????????,来谁补充
SystemId是http://www. xxxxxx.com/address.xsdSystemId是用来验证XML文件的Schema存放的地方, 可以想象没底需要的时候去http://java.sun.com/dtd/web-app_2_3.dtd这样的地址去找是不现实和低效的,解决这个问题可以采用象EntityResolver这样的接口来替换在本地搜索
比如public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
{
if (systemId.equals("http://www.syn.com/xxxxxxxxx/address.xsd"))
{
return new InputSource(new FileInputStream("D:/PROJECT/STUDY/xml/address.xsd"));
} else {
return null;
}
}记着给分
一,对于以DTD为Schema的XML文件
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">publicId是-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN
SystemId是http://java.sun.com/dtd/web-app_2_3.dtd二,对于以xsd为Schema的XML文件
<syn:address xmlns:syn="http://www.xxxxxx.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.xxxxxx.com/ http://www. xxxxxx.com/address.xsd">publicId是?????????,来谁补充
SystemId是http://www. xxxxxx.com/address.xsdSystemId是用来验证XML文件的Schema存放的地方, 可以想象没底需要的时候去http://java.sun.com/dtd/web-app_2_3.dtd这样的地址去找是不现实和低效的,解决这个问题可以采用象EntityResolver这样的接口来替换在本地搜索
比如public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
{
if (systemId.equals("http://www.syn.com/xxxxxxxxx/address.xsd"))
{
return new InputSource(new FileInputStream("D:/PROJECT/STUDY/xml/address.xsd"));
} else {
return null;
}
}记着给分
解决方案 »
- 急急急!!!上传图像插件
- Could not roll back Hibernate transaction在线等!!!求大神
- 关于调用DB2存储过程的问题
- 高手都进来!!如果禁止关闭Javascript??????????
- 谁能解释java:comp/env/? 100分.............
- 利用java Api打印JTable(欢迎大家一起来讨论)
- <ejb-link> </ejb-link> 是什么意思呀
- 初级问题:app server、web server、http server这三者有什么区别和联系?
- [初学请教]学j2se还是j2ee?(保证大家都有分,快来看看)
- 如何自学java
- 哪位能够告诉我tapestry的运行机制阿!!!!!
- ajax+struts 的级联菜单问题~!~!
同时再问一下:
XMLReader reader = XMLReaderFactory.createXMLReader(
"org.apache.xerces.parsers.SAXParser");
reader.parse(new InputSource("contents.xml");通过这种方式解析XML文件的时候,会试图到网上下载相关的DTD和XSD,有java.net.ConnectionException异常产生,因为连不上。只能通过像上面那种
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
{
if (systemId.equals("http://www.syn.com/xxxxxxxxx/address.xsd"))
{
return new InputSource(new FileInputStream("D:/PROJECT/STUDY/xml/address.xsd"));
} else {
return null;
}
}
来解决么???