举例说明比较容易
一,对于以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;
}
}记着给分
解决方案 »
- struts2 webwork上传文件错误问题
- 如何通过httpclient读取flash中的数据
- 求hibernate映射文件的写法
- 急求用java/c++/c#解决获取摄像头数据并合成三维图像进行处理
- spring注入的问题
- 关于smack jabber客户端文件传输的问题
- 高分请教几个专业名词 !
- 一个关于用javamail发邮件的问题,快折腾疯了!
- 救命,WEBLOGIC7抛出java.net.SocketException,搞得程序很慢,但一分钟后又好了
- Struts bean:write 布尔型格式化,字符截取问题
- 哪位能够告诉我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;
}
}
来解决么???