xml文件中包含一個這樣的元素:
<element5 xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
如果用sun的jdk1.4.2就沒這個問題.
異常詳細信息如下 :
Root cause: java.lang.IllegalStateException: can't declare any more prefixes in this context
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:691)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:287)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:583)
原因分析:
是由於xml parser: Crimson不能解釋帶有類似於xmlns:xsi這樣的屬性.要用Xerces才行,但是IBM的jre在默認情況下尋找Crimson作爲parser解決辦法是通過在程序中設定jre的xml parser爲Xerces,同時將Xerces的jar包加入到classpath中,一共有三個包:xalan.jar,xercesImpl.jar,xml-apis.jar
從http://xml.apache.org/xalan-j/上可以下載.
http://xerces.apache.org/xerces-j/
jre的xml parser設置:是jrelib下的一個叫jaxp.properties文件,最後有三行是關於指定 xml parser的,將註釋去掉,或者在程序中加入以下語句也可以:
System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory","org.apache.xerces.jaxp.SAXParserFactoryImpl");
如下鏈接中的文章解釋得非常具體:
http://www.javaworld.com.tw/jute/post/view?bid=19&id=14958&sty=3
/IBM/WebSphere/AppServer/java/jre/lib/
目錄下增加 三個架包
xercesImpl.jar
xalan.jar
xml-apis.jar
建立文件jaxp.properties
內容如下:
javax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl
javax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
javax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl