首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

ibatis的cacheModel配备不满足"(flushInterval?flushOnExecute*property*)+"约束

2012-06-29 
ibatis的cacheModel配置不满足(flushInterval?,flushOnExecute*,property*)+约束给ibatis加cache时, 碰

ibatis的cacheModel配置不满足"(flushInterval?,flushOnExecute*,property*)+"约束
给ibatis加cache时, 碰到一直报"The content of element type "cacheModel" must match "(flushInterval?,flushOnExecute*,property*)+". " 这个异常. 查了头天, 自己的格式完全符合, 最后把这些文件找出来单独验证. 我的XML:

card.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "\bin\validateXML\sql-map.dtd"><sqlMap namespace="card"> <cacheModel id="product-cache" type="LRU"><flushInterval hours="24"/>  <flushOnExecute statement="insertProduct"/><flushOnExecute statement="updateProduct"/><flushOnExecute statement="deleteProduct"/><property name="size" value="1000" /></cacheModel></sqlMap>

sql-map.dtd的cacheModel部分:
<!ELEMENT cacheModel (flushInterval?, flushOnExecute*, property*)+><!ATTLIST cacheModelid CDATA #REQUIREDtype CDATA #REQUIREDreadOnly (true | false) #IMPLIEDserialize (true | false) #IMPLIED>

使用验证程序:
import java.io.FileNotFoundException;import java.io.IOException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.xml.sax.SAXException;public class ValidateXMLDTD {        public static void main(String[] args) {        testXML();    }        public static void testXML() {        try {            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();            dbf.setValidating(true);            DocumentBuilder db = dbf.newDocumentBuilder();            db.parse(ValidateXMLDTD.class.getResourceAsStream("card.xml"));        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (ParserConfigurationException e) {            e.printStackTrace();        } catch (SAXException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }    }   }


其中sql-map.dtd给的example:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "\bin\validateXML\sql-map.dtd"><sqlMap namespace="card"> <cacheModel id="product-cache" type="LRU"><flushInterval hours="24"/><flushOnExecute statement="insertProduct"/><flushOnExecute statement="updateProduct"/><flushOnExecute statement="deleteProduct"/><property name="size" value="1000" /></cacheModel></sqlMap>


在内容上无论怎么比较都一样, 最后一句一句的替换, 看到底错在哪句上面, 还是会报错, 最终只感觉内容完全一样, 只是不美观, 格式化一下, 再测试, 发现没有错, 原来是自的XML的flushOnExecute前多了一个空格, dtd给出"(flushInterval?, flushOnExecute*, property*)+" 这种约束时元素中间不能出现空格, 但可以使用制表符, 当dtd给出"(#PCDATA | include | dynamic | iterate)"约束时, 元素中间既可以是空格, 也可以是制表符.

删除空格, 使用tab键, 大功告成.....

热点排行