<HTML xmlns:eXclaimer="http://www.exclaimer.co.uk">
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-16">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6603.0">
<TITLE>Help Needed with JDOM</TITLE>
</HEAD><BODY ><DIV>
<!-- Converted from text/rtf format -->
<P> <FONT SIZE=2 FACE="Arial">Hi Folks,</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">I'm trying to parse and validate a xml document but I get the following error…</FONT>
</P>
<P> <B> <FONT SIZE=2 FACE="Arial">java.net.MalformedURLException: null: java.lang.NullPointerException</FONT></B>
</P>
<P> <FONT SIZE=2 FACE="Arial">Here is the copy of my source ValidDocument….</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">import java.io.File;</FONT>
<BR> <FONT SIZE=2 FACE="Arial">import java.io.FileInputStream;</FONT>
<BR> <FONT SIZE=2 FACE="Arial">import java.io.*;</FONT>
<BR> <FONT SIZE=2 FACE="Arial">import java.io.InputStream;</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">import org.jdom.*;</FONT>
<BR> <FONT SIZE=2 FACE="Arial">import org.jdom.Document;</FONT>
<BR> <FONT SIZE=2 FACE="Arial">import org.jdom.JDOMException;</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">import org.jdom.transform.*;</FONT>
<BR> <FONT SIZE=2 FACE="Arial">import org.jdom.contrib.input.*;</FONT>
<BR> <FONT SIZE=2 FACE="Arial">import org.jdom.output.*;</FONT>
<BR> <FONT SIZE=2 FACE="Arial">import org.jdom.input.*;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">/**</FONT>
<BR><FONT SIZE=2 FACE="Arial"> * Class ValidDocument provides an XML document validated agains the schema.</FONT>
<BR><FONT SIZE=2 FACE="Arial"> * @author Rajesh Anand</FONT>
<BR><FONT SIZE=2 FACE="Arial"> */</FONT>
<BR> <FONT SIZE=2 FACE="Arial">public class ValidDocument {</FONT>
</P>
<P>
</P>
<P><FONT SIZE=2 FACE="Arial"> public static Document build(InputStream xmlFile, String xmlSchema)</FONT>
<BR>
<BR><FONT SIZE=2 FACE="Arial"> throws JDOMException, IOException {</FONT>
<BR> <FONT SIZE=2 FACE="Arial">Document doc1 = null; </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> // Create new SAXBuilder, using default parser</FONT>
<BR><FONT SIZE=2 FACE="Arial"> SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">System.out.println("So far so good");</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> // Uncommenting the following line ensures that the document received stands alone</FONT>
<BR><FONT SIZE=2 FACE="Arial"> // builder.setFeature("<A HREF="http://apache.org/xml/features/nonvalidating/load-external-dtd">http://apache.org/xml/features/nonvalidating/load-external-dtd</A>", false);</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> builder.setFeature("<A HREF="http://apache.org/xml/features/validation/schema">http://apache.org/xml/features/validation/schema</A>", true);</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">System.out.println("So far so good, after feature set"); </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">// builder.setProperty(</FONT>
<BR><FONT SIZE=2 FACE="Arial">// "</FONT><A HREF="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation</FONT></U></A><FONT SIZE=2 FACE="Arial">",</FONT>
<BR><FONT SIZE=2 FACE="Arial">// "</FONT><A HREF="file:///"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">file:///</FONT></U></A><FONT SIZE=2 FACE="Arial">" + xmlSchema);</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">builder.setProperty(</FONT>
<BR><FONT SIZE=2 FACE="Arial"> "</FONT><A HREF="http://apache.org/xml/properties/schema"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://apache.org/xml/properties/schema</FONT></U></A><FONT SIZE=2 FACE="Arial">"</FONT>
<BR><FONT SIZE=2 FACE="Arial"> + "/external-noNamespaceSchemaLocation",</FONT>
<BR><FONT SIZE=2 FACE="Arial"> xmlSchema.toURL().toString() );</FONT>
</P>
<BR>
<P> <FONT SIZE=2 FACE="Arial">System.out.println( "Successfully parsed and validated" );</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">System.out.println("Property set");</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">try{</FONT>
<BR><FONT SIZE=2 FACE="Arial"> doc1 = builder.build(xmlFile);</FONT>
<BR> <FONT SIZE=2 FACE="Arial">} </FONT>
<BR> <FONT SIZE=2 FACE="Arial">catch(Exception e){</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">System.out.println(e.getMessage());</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">}</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> return doc1;</FONT>
<BR>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> public static void main(String[] args) {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> if (args.length < 2) {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> System.err.println("Usage: java demo.ValidDocument <fileLocation> <xmlSchemaLocation>");</FONT>
<BR> <FONT SIZE=2 FACE="Arial">return;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> } </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> try {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> InputStream xmlFile = Thread.currentThread().getContextClassLoader()</FONT>
<BR><FONT SIZE=2 FACE="Arial"> .getSystemResourceAsStream(args[0]);</FONT>
<BR>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">Document doc = ValidDocument.build(xmlFile, args[1]);</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">System.out.println("File created");</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> // Output the document to System.out</FONT>
<BR><FONT SIZE=2 FACE="Arial"> XMLOutputter outputter = new XMLOutputter();</FONT>
<BR><FONT SIZE=2 FACE="Arial"> outputter.output(doc, System.out);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
<BR><FONT SIZE=2 FACE="Arial"> catch (Exception e) {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> e.printStackTrace();</FONT>
<BR><FONT SIZE=2 FACE="Arial"> System.exit(1);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> System.exit(0);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
<BR> <FONT SIZE=2 FACE="Arial">}</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">Any help will be greatly appreciated. Thanks in advance.</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">rgds,</FONT>
</P>
<P><B><FONT SIZE=2 FACE="Arial">Rajesh Anand</FONT></B>
<BR><B><FONT SIZE=2 FACE="Arial">Email:Rajesh_anand@ml.com</FONT></B>
</P>
</DIV>
<DIV>
<HR COLOR="gray">
</DIV>
<DIV>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. <A HREF="http://www.ml.com/email_terms/">Click here </A>for important additional terms relating to this e-mail. <A HREF="http://www.ml.com/email_terms/">http://www.ml.com/email_terms/</A></DIV>
<DIV>
<HR COLOR="gray">
</DIV></BODY></HTML>