Avatar billede fredand Forsker
21. juli 2006 - 10:21 Der er 4 kommentarer og
1 løsning

How to use DOM level 3 in Java 1.4.0?

Hello!

We are forced to developing under Java 1.4.0 since a ceratin databasapplication that we build our app on just support 1.4.

How ever I need to use this method in in the org.w3c.dom.Node
interface: boolean isEqualNode(Node arg)

Unfortunately this method is only implemented in Java 1.5 and not in 1.4 since 1.4 do not support DOM Level 3. According to:
http://java.sun.com/javase/technologies/compatibility.jsp

"JAXP - The J2SE 1.4 platform supported the DOM Level 2 API. The J2SE 5.0 platform supports the DOM Level 3 family of APIs. New methods have been added to DOM Level 3 interfaces, so some existing applications using DOM Level 2 will not be able to compile with the new interfaces.
Many DOM Level 2 applications will run if DOM Level 3 is substituted for DOM Level 2 in the class path; however, a small number will encounter a NoSuchMethodException. Therefore, some applications will not have binary compatibility."

If I understand the text above I should be able to add the needed class in my classpath.

I find the class org.w3c.dom.Node in my computer at:

C:\Program Files\Java\j2re1.4.0\lib/rt.jar
C:\Program Files\Java\j2re1.4.2_03\lib/rt.jar
C:\Program Files\Java\j2sdk1.4.0\jre\lib/rt.jar
C:\Program Files\Java\jdk1.5.0_06\jre\lib/rt.jar
C:\Program Files\Java\jre1.5.0_06\lib/rt.jar

I guess the newest org.w3c.dom.Node is in the jars at:
C:\Program Files\Java\jre1.5.0_06

But how do I add it in a proper way to my classpath?
Should I extract it from rt.jar and put it in an other jar and add that path first in my classpath?

Is that the correct way to solve this?

Of course there is on other way like implement the isEqualNode my self:
The two nodes are of the same type.
The following string attributes are equal: nodeName, localName, namespaceURI, prefix, nodeValue . This is: they are both null, or they have the same length and are character for character identical.
"The attributes NamedNodeMaps are equal. This is: they are both null, or they have the same length and for each node that exists in one map there is a node that exists in the other map and is equal, although not necessarily at the same index.
The childNodes NodeLists are equal. This is: they are both null, or they have the same length and contain equal nodes at the same index. Note that normalization can affect equality; to avoid this, nodes should be normalized before being compared. "

But this seems a bit harder and more risky.

So if you have any suggetsion how to attack this problem in the best way please let me know!

Best regards
Fredrik
Avatar billede arne_v Ekspert
22. juli 2006 - 03:18 #1
try and look at the following:

C:\>type Test.java
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Test {
    public static void main(String[] args) {
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.newDocument();
            Element one1 = doc.createElement("one");
            Element one2 = doc.createElement("one");
            System.out.println(one1.isEqualNode(one2));
        } catch (FactoryConfigurationError e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }
        return;
    }
}
C:\>call jdk150def

C:\>java -version
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

C:\>javac -source 1.4 -target 1.4 Test.java

C:\>java Test
true

C:\>call jdk142def

C:\>java -version
java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)

C:\>java Test
Exception in thread "main" java.lang.NoSuchMethodError: org.w3c.dom.Element.isEq
ualNode(Lorg/w3c/dom/Node;)Z
        at Test.main(Test.java:20)

C:\>java -Djava.endorsed.dirs=C:\Jakarta\xerces-2_8_0 -Djavax.xml.parsers.Docume
ntBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -classpath .;
C:\Jakarta\xerces-2_8_0\xml-apis.jar;C:\Jakarta\xerces-2_8_0\xercesImpl.jar Test

true
Avatar billede arne_v Ekspert
22. juli 2006 - 03:20 #2
you can not specify -D for javac but maybe you can still get javac to pick
up classes from the default endorsed dirs

else 1.5 and -source 1.4 -target 1.4 should be OK
Avatar billede arne_v Ekspert
11. september 2006 - 23:54 #3
any luck ?
Avatar billede fredand Forsker
29. december 2010 - 21:02 #4
Hello!

In some way I missed this thread along the way!

You really should give a svar so I can reward you mate!

(I feel ashamed for this late reply)

Best regards
Fredrik
Avatar billede arne_v Ekspert
29. december 2010 - 21:08 #5
ok
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester