您的位置:首页 > Web前端

How to switch bewteen differenct JAXP?

2008-07-23 17:42 309 查看
How to switch bewteen differenct JAXP

1 JAXP in Sun JDK uses the implementation from Apache Xerces by default. But we can change it by setting the system properties.
1.1 How to use the Oracle JAXP implementation?
1.1.1 Find the jar - JDEVELOPER_HOME/lib/xmlparserv2.jar
1.1.2 Put the jar in the classpath.
1.1.3 Set the system variants in the JVM startup.
-Djavax.xml.transform.TransformerFactory=oracle.xml.jaxp.JXSAXTransformerFactory
-Djavax.xml.parsers.SAXParserFactory=oracle.xml.jaxp.JXSAXParserFactory
-Djavax.xml.parsers.DocumentBuilderFactory=oracle.xml.jaxp.JXDocumentBuilderFactory
1.2 How to use the apache xerces JAXP implementation?
-Djavax.xml.transform.TransformerFactory=com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

2 How to use the CDATA section to store the raw data in xml file? With the CDATA section, parser or builder encapsulate the raw data within <![CDATA[ and ]] theorially. But for different implementations, it leads to differenct results. Sometimes it decides if it should encapsulate the raw data based on if it is necesary. Sometimes the raw data are legal from the start, so it ignores it. Sometimes not.
2.1 Program:
Element eTemp = document.createElement("value");
String sValue = "test-legal";
Node nodeValue = document.createCDATASection(vlaue);
eTemp.appendChild(nodeValue);
2.2 Result:

Apache JAXP Impl - Windows
<![CDATA[test-legal]]

Apache JAXP Impl - Linux
test-legal

Oracle JAXP Impl - Windows
test-legal

Oracle JAXP Impl - Linux
test-legal

2.3 Program:
Element eTemp = document.createElement("value");
String sValue = "test-legal<><><>";
Node nodeValue = document.createCDATASection(vlaue);
eTemp.appendChild(nodeValue);
2.4 Result:

Apache JAXP Impl - Windows
<![CDATA[test-legal<><><>]]

Apache JAXP Impl - Linux
<![CDATA[test-legal<><><>]]

Oracle JAXP Impl - Windows
<![CDATA[test-legal<><><>]]

Oracle JAXP Impl - Linux
<![CDATA[test-legal<><><>]]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: