You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Vadym Krevs <Va...@merant.com> on 2001/01/18 19:39:02 UTC
xerces and IBM Java2
I've encoutered an interesting bug concerning xerces-1.2.3. On my computer I
have two JDK installed:
1) IBM Java2
java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Classic VM (build 1.3.0, J2RE 1.3.0 IBM build cn130-20001124 (JIT enabled:
jitc)
2) Suns Java2
java.exe -version
java version "1.3.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)
Below you will find sources of two files, TestXML.java and req_getwork1.xml.
If I compile and execute the TestXML.java file using Sun's JDK the output is
GetWork
GetWork
however if I compile and execute the TestXML.java file using IBM's JDK the
output becomes
GetWork
null.
It appears that the local name of the <GetWork> element is null for IBM's
JDK, whereas for Sun's JDK it is GetWork - as it should be. Is it a xerces
bug or IBM's VM bug?
Thanks,
Vadym
----------------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------------------
Source of req_getwork1.xml
----------------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------------------
<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAP-ENV:Body>
<GetWork xmlns="http://www.somenamespace.com">
<user id="user" password="password" version="1"/>
</GetWork>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
----------------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------------------
Source of TestXML.java :
----------------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------------------
import java.io.*;
import org.apache.xerces.parsers.*;
import org.xml.sax.*;
import org.w3c.dom.traversal.*;
import org.w3c.dom.*;
public class TestXML
{
static public void main(String args[])
{
try{
FileReader reader = new FileReader("req_getwork1.xml");
DOMParser parser = new org.apache.xerces.parsers.DOMParser();
parser.parse(new InputSource(reader));
Document doc = parser.getDocument();
Element eltRoot = doc.getDocumentElement();
Element eltSoapBody = getSingleElement(eltRoot,
"SOAP-ENV:Body");
Element eltMethod = getFirstElement(eltSoapBody);
String strTagName = eltMethod.getTagName();
String strMethodName = eltMethod.getLocalName();
System.out.println(strTagName);
System.out.println(strMethodName);
}
catch(Exception e)
{
System.err.println(e.getMessage());
}
}
static public Element getSingleElement (Element el, String strNodeName)
{
String sRet = null;
NodeList nodes = el.getElementsByTagName(strNodeName);
int nLength = nodes.getLength();
if (nodes != null && nodes.getLength() == 1)
{
Node node = nodes.item(0);
if (node.getNodeType() == Node.ELEMENT_NODE)
return (Element)node;
}
return null;
}
static public Element getFirstElement (Element el)
{
String sRet = null;
NodeList nodes = el.getChildNodes();
if (nodes != null)
{
int nLength = nodes.getLength();
for (int i = 0; i < nLength; i++)
{
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
return (Element)node;
}
}
return null;
}
}
Vadym Krevs
MERANT
Email: Vadym.Krevs@merant.com
Phone: +44 (0) 1635 565215
Address: Merant International Ltd.
The Lawn, 22-30 Old Bath Road
Newbury, Berkshire, RG14 1QN
UK