I have found the BUG
The Version 3.1.0 from IBM's XML4Java Parser has a Bug.
I downloaded the old 3.0.1 version, and with that one it works perfect.... :-)
this little bug from IBM has consumed 3 days from my valuable diploma work.... :-(
but now i can go on, and do something more useful
thanks for your help
Pascal Troxler
University of Applied Sciences, Biel
Switzerland
unfortunately it realy does not work.
i have tried with the ClassLoader.getSystemResourceAsSream("xyz.xml") and
i put the file into the classpath directory. i also tried to put it into the classpath which is
defined in the JRUN Admin console.
Same proplem if i use full path (like "c:/mystuff/myfile.xml")
and i also tried to access the file via URL from the Webserver (which is anyway running).
But in that case JRUN immediately crashes.
if im running the code from a DOS shell, it works well. but if i use the exactly same
code in a JSP, then the file cant be found.
The test code is like this: (The JSP code is identic)
public class test {
public static void main ( String [] args ) {
try {
ConfigReader config = ConfigReader.getInstance();
config.parseConfig();
String logo = config.getLogo();
System.out.println ("Logo: " + logo );
} catch (Exception e) {
System.out.println (e);
}
}
}
******************
import org.apache.xerces.parsers.DOMParser;
public class ConfigReader {
private static ConfigReader instance;
public static ConfigReader getInstance ( ) {
if ( instance == null ) instance = new ConfigReader ( );
return instance;
}
public static void parseConfig ( ) throws Exception {
DOMParser parser = new DOMParser();
Node rootNode = null;
Document document = null;
InputStream is = ClassLoader.getSystemResourceAsStream ( "config.xml" );
System.out.println ( "Input Stream: " + is );
parser.parse ( new InputSource ( is ) );
document = parser.getDocument();
............
}
.....
}
The InputStream object is NULL and also document is NULL after calling this method.
Thanks for Help
Pascal Troxler
University of Applied Sciences, Biel
I would say that the JVM is searching for the file in its home directory.
I am not sure where that would be in JRun.
Here is a more reliable solution. Put the file in the JVMs classpath.
Then use the following code to retrieve and parse.
InputStream input = ClassLoader.getSystemResourceAsStream( "myxmlfile.xml");
parser.parse( new InputSource( input ) );
This should work. I have used it many times before.
Here is an example of how to set the classpath.
C:\junk\myxmlfile.xml
The classpath should include this directory:
C:\junk\
Once you have this all set up it will work.
There are many other solutions. You can use a web server to serve-up the
xml file that you desire, or specify the path directly in the parse method.
You will have to choose the one that best fits your situation.
Adam
*******************************************************************************************************
>How are you accessing the XML file?
>Are you using ClassLoader.getResourceAsStream( "filename" )?
>Need some more information before I can give you a hand.
>Adam
The code is like this:
import org.xml.sax.*;
import org.w3c.dom.*;
import org.apache.xerces.parsers.DOMParser;
....
public void parse ( ) {
DOMParser parser = new DOMParser();
try {
parser.setFeature("
http://apache.org/xml/features/dom/defer-node-expansion",
false);
parser.setFeature("
http://apache.org/xml/features/continue-after-fatal-error",
true);
parser.setFeature("
http://apache.org/xml/features/allow-java-encodings",
true);
parser.parse ( "myxmlfile.xml" );
Document document = parser.getDocument();
NodeList list = document.getChildNodes();
.....
} catch (Exception e) {
....
}
*******
