[jdom-interest] Help Needed with JDOM
Anand, Rajesh
Rajesh_Anand at ml.com
Sat Dec 25 16:29:32 PST 2004
Hi Folks,
I'm trying to parse and validate a xml document but I get the
following error...
java.net.MalformedURLException: null:
java.lang.NullPointerException
Here is the copy of my source ValidDocument....
import java.io.File;
import java.io.FileInputStream;
import java.io.*;
import java.io.InputStream;
import org.jdom.*;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.transform.*;
import org.jdom.contrib.input.*;
import org.jdom.output.*;
import org.jdom.input.*;
/**
* Class ValidDocument provides an XML document validated agains the
schema.
* @author Rajesh Anand
*/
public class ValidDocument {
public static Document build(InputStream xmlFile, String
xmlSchema)
throws JDOMException, IOException {
Document doc1 = null;
// Create new SAXBuilder, using default parser
SAXBuilder builder = new
SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
System.out.println("So far so good");
// Uncommenting the following line ensures that the document
received stands alone
//
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-ex
ternal-dtd", false);
builder.setFeature("http://apache.org/xml/features/validation/schema",
true);
System.out.println("So far so good, after feature set");
// builder.setProperty(
//
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocat
ion",
// "file:///" + xmlSchema);
builder.setProperty(
"http://apache.org/xml/properties/schema"
+ "/external-noNamespaceSchemaLocation",
xmlSchema.toURL().toString() );
System.out.println( "Successfully parsed and validated" );
System.out.println("Property set");
try{
doc1 = builder.build(xmlFile);
}
catch(Exception e){
System.out.println(e.getMessage());
}
return doc1;
}
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Usage: java demo.ValidDocument
<fileLocation> <xmlSchemaLocation>");
return;
}
try {
InputStream xmlFile =
Thread.currentThread().getContextClassLoader()
.getSystemResourceAsStream(args[0]);
Document doc = ValidDocument.build(xmlFile, args[1]);
System.out.println("File created");
// Output the document to System.out
XMLOutputter outputter = new XMLOutputter();
outputter.output(doc, System.out);
}
catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
System.exit(0);
}
}
Any help will be greatly appreciated. Thanks in advance.
rgds,
Rajesh Anand
Email:Rajesh_anand at ml.com
--------------------------------------------------------
If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail. http://www.ml.com/email_terms/
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20041226/6c4b260e/attachment.htm
More information about the jdom-interest
mailing list