上一篇,在Websphere上使用Axis做的客戶端調用Webservice要進行修改配置的原因

     之所以要修改配置,是因爲SUN JDK和IBM Webspher JDK 對Axis的代碼解釋不一樣,詳細可以參考以下(轉自Houying的Blog):

     IBM AIX Websphere jdk1.4 下 can't declare any more prefixes in this context 問題的解決過程

     jdom/dom4j在解釋xml時,用的是ibm的jre 1.4.1時,如果xml文件中有xmlns:udm時,就會在將string input stream轉成document時出現:java.lang.IllegalStateException: can't declare any more prefixes in this context錯誤,請教各位大蝦這問題怎麼解決?,

     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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章