  | |  | Bug in parser? | Bug in parser? 2003-05-30 - By Jacob Kjome
I can tell you exactly why it didn't find it. getClass().getResourceAsStream("test.xml") looks for the test.xml file in the same package as your class exists and nowhere else. If you want to find test.xml in the root of the classpath, then do either getClass().getResourceAsStream("/test.xml") or getClass().getClassLoader().getResourceAsStream("test.xml")
Jake
At 01:46 PM 5/29/2003 -0700, you wrote: >Thank you that was the issue. Although I'm not sure >why getClass().getResourceAsStream(testDoc); was not >able to find a file that was present in the >/WEB-INF/classes directory! Changing the servlet >initialization code to >context.getResourceAsStream("/WEB-INF/classes/" + >testDoc); worked! > >Thanks again, >Jon > >--- Michael Rafael Glavassevich ><mrglavas@(protected)> wrote: > > Hi Jon, > > > > You might want to check if you're passing in a > > non-null InputStream. I > > believe getResourceAsStream (unless your class was > > loaded by some custom > > ClassLoader), searches the classpath for the > > resource you want, so if > > you've only have jars in your classpath, I doubt it > > would search in the > > file system. > > > > ----------------------------------------- > > Michael Glavassevich > > mrglavas@(protected) > > Candidate for Bachelor of Applied Science > > Computer Engineering > > University of Waterloo > > > > On Tue, 27 May 2003, Jon Wilmoth wrote: > > > > > I've tried simplifying the test by attempting to > > parse > > > a document without a dtd reference. > > > > > > <?xml version="1.0"?> > > > <test>sample</test> > > > > > > The java code I use, which still results in an > > > exception is: > > > > > > log.debug("TRYING TO PARSE SIMPLE DOCUMENT..."); > > > SAXBuilder builder = new SAXBuilder(false); > > > builder.setIgnoringElementContentWhitespace(true); > > > > > >builder.setFeature("http://xml.org/sax/features/validation", > > > false); > > > > > > String testDoc = "test.xml"; > > > try { > > > Document doc = > > > > > >builder.build(getClass().getResourceAsStream(testDoc)); > > > > > > //I never get here! > > > log.debug("Successfully parsed test > > document!"); > > > > > > } catch (JDOMException jdome) { > > > Throwable root = jdome.getCause(); > > > if (root != null) { > > > log.error("Root cause:" + > > root.getMessage()); > > > } > > > log.error("Failed to parse " + testDoc + " > > file", > > > root); > > > } > > > > > > > > > --- Michael Rafael Glavassevich > > > <mrglavas@(protected)> wrote: > > > > Hi Jon, > > > > > > > > It would be great if you posted a snippet of > > code > > > > before and including > > > > the invocation of SAXBuilder.build, in order to > > > > diagnose your problem. It > > > > seems that there is something wrong with the > > > > location specified for your > > > > XML file (either an invalid URI, or java.net.URL > > > > doesn't recognize the > > > > protocol/scheme of the URI). In either case, > > Xerces > > > > is unable to read > > > > your file. > > > > > > > > As a separate issue, I noticed that the system > > ID > > > > that you specified for > > > > your DTD is not a valid URI. It should be > > > > > > "file:///C:/temp/projects/EventRegistrations.dtd" > > > > instead of > > > > > > "file:///C:\temp\projects\EventRegistrations.dtd" > > > > ('\' isn't a valid URI > > > > character). Xerces (by default) will fix up the > > > > system ID before it's > > > > used. However, if you want your documents to be > > > > portable across different > > > > XML parsers, then you need to make sure that > > URIs > > > > you specify actually > > > > meet the URI spec. > > > > > > > > Hope that helps. > > > > > > > > ----------------------------------------- > > > > Michael Glavassevich > > > > mrglavas@(protected) > > > > Candidate for Bachelor of Applied Science > > > > Computer Engineering > > > > University of Waterloo > > > > > > > > On Sat, 24 May 2003, Jon Wilmoth wrote: > > > > > > > > > I'm trying to parse a very simple xml document > > > > with > > > > > xerces 2.4.0. Unfortunately I get the > > following > > > > > error: > > > > > > > > > > java.net.MalformedURLException > > > > > at java.net.URL.<init>(URL.java:613) > > > > > at java.net.URL.<init>(URL.java:476) > > > > > at java.net.URL.<init>(URL.java:425) > > > > > at > > > > > > > > > > > > > > >org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown > > > > > Source) > > > > > at > > > > > > > > > > > > > > >org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown > > > > > Source) > > > > > at > > > > > > > > > > > > > > >org.apache.xerces.parsers.XML11Configuration.parse(Unknown > > > > > Source) > > > > > at > > > > > > > > > > > > > > >org.apache.xerces.parsers.DTDConfiguration.parse(Unknown > > > > > Source) > > > > > at > > > > > > > org.apache.xerces.parsers.XMLParser.parse(Unknown > > > > > Source) > > > > > at > > > > > > > > > > > > > > >org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown > > > > > Source) > > > > > at > > > > > > > > > > > org.jdom.input.SAXBuilder.build(SAXBuilder.java:354) > > > > > at > > > > > > > > > > > org.jdom.input.SAXBuilder.build(SAXBuilder.java:673) > > > > > > > > > > The document: > > > > > <?xml version="1.0"?> > > > > > <!DOCTYPE EventRegistrations SYSTEM > > > > > > > "file:///C:\temp\projects\EventRegistrations.dtd"> > > > > > <EventRegistrations> > > > > > <event > > > > name="test.events.BusinessObjectChangeEvent"> > > > > > > > <listener>test.ObjectCreationListener</listener> > > > > > </event> > > > > > </EventRegistrations> > > > > > > > > > > Passes validation in my xml editor. What's > > going > > > > on? > > > > > > > > > > > __________________________________ > > > Do you Yahoo!? > > > The New Yahoo! Search - Faster. Easier. Bingo. > > > http://search.yahoo.com > > > > > > > > >--------------------------------------------------------------------- > > > To unsubscribe, e-mail: > > xerces-j-user-unsubscribe@(protected) > > > For additional commands, e-mail: > > xerces-j-user-help@(protected) > > > > > > > >--------------------------------------------------------------------- > > To unsubscribe, e-mail: > > xerces-j-user-unsubscribe@(protected) > > For additional commands, e-mail: > > xerces-j-user-help@(protected) > > > > >__________________________________ >Do you Yahoo!? >Yahoo! Calendar - Free online calendar with sync to Outlook(TM). >http://calendar.yahoo.com > >--------------------------------------------------------------------- >To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) >For additional commands, e-mail: xerces-j-user-help@(protected)
<html> <body> <font size=3><br> I can tell you exactly why it didn't find it. getClass().getResourceAsStream("test.xml") looks for the test.xml file in the same package as your class exists and nowhere else. If you want to find test.xml in the root of the classpath, then do either getClass().getResourceAsStream("/test.xml") or getClass().getClassLoader().getResourceAsStream("test.xml")<br><br> Jake<br><br> At 01:46 PM 5/29/2003 -0700, you wrote:<br> <blockquote type=cite class=cite cite>Thank you that was the issue. Although I'm not sure<br> why getClass().getResourceAsStream(testDoc); was not<br> able to find a file that was present in the<br> /WEB-INF/classes directory! Changing the servlet<br> initialization code to<br> context.getResourceAsStream("/WEB-INF/classes/" +<br> testDoc); worked!<br><br> Thanks again,<br> Jon<br><br> --- Michael Rafael Glavassevich<br> <mrglavas@(protected)> wrote:<br> > Hi Jon,<br> > <br> > You might want to check if you're passing in a<br> > non-null InputStream. I<br> > believe getResourceAsStream (unless your class was<br> > loaded by some custom<br> > ClassLoader), searches the classpath for the<br> > resource you want, so if<br> > you've only have jars in your classpath, I doubt it<br> > would search in the<br> > file system.<br> > <br> > -----------------------------------------<br> > Michael Glavassevich<br> > mrglavas@(protected)<br> > Candidate for Bachelor of Applied Science<br> > Computer Engineering<br> > University of Waterloo<br> > <br> > On Tue, 27 May 2003, Jon Wilmoth wrote:<br> > <br> > > I've tried simplifying the test by attempting to<br> > parse<br> > > a document without a dtd reference.<br> > ><br> > > <?xml version="1.0"?><br> > > <test>sample</test><br> > ><br> > > The java code I use, which still results in an<br> > > exception is:<br> > ><br> > > log.debug("TRYING TO PARSE SIMPLE DOCUMENT...");<br> > > SAXBuilder builder = new SAXBuilder(false);<br> > > builder.setIgnoringElementContentWhitespace(true);<br> > ><br> ><br> builder.setFeature("<a href="http://xml.org/sax/features/validation" eudora="autourl">http://xml.org/sax/features/validation</a>",<br> > > false);<br> > ><br> > > String testDoc = "test.xml";<br> > > try {<br> > > Document doc =<br> > ><br> ><br> builder.build(getClass().getResourceAsStream(testDoc));<br> > ><br> > > //I never get here!<br> > > log.debug("Successfully parsed test<br> > document!");<br> > ><br> > > } catch (JDOMException jdome) {<br> > > Throwable root = jdome.getCause();<br> > > if (root != null) {<br> > > log.error("Root cause:" +<br> > root.getMessage());<br> > > }<br> > > log.error("Failed to parse " + testDoc + "<br> > file",<br> > > root);<br> > > }<br> > ><br> > ><br> > > --- Michael Rafael Glavassevich<br> > > <mrglavas@(protected)> wrote:<br> > > > Hi Jon,<br> > > ><br> > > > It would be great if you posted a snippet of<br> > code<br> > > > before and including<br> > > > the invocation of SAXBuilder.build, in order to<br> > > > diagnose your problem. It<br> > > > seems that there is something wrong with the<br> > > > location specified for your<br> > > > XML file (either an invalid URI, or java.net.URL<br> > > > doesn't recognize the<br> > > > protocol/scheme of the URI). In either case,<br> > Xerces<br> > > > is unable to read<br> > > > your file.<br> > > ><br> > > > As a separate issue, I noticed that the system<br> > ID<br> > > > that you specified for<br> > > > your DTD is not a valid URI. It should be<br> > > ><br> > "<a href="file://C:\temp\projects\EventRegistrations.dtd" eudora="autourl" >file:///C:/temp/projects/EventRegistrations.dtd</a>"<br> > > > instead of<br> > > ><br> > "<a href="file://C:\temp\projects\EventRegistrations.dtd" eudora="autourl" >file:///C:\temp\projects\EventRegistrations.dtd</a>"<br> > > > ('\' isn't a valid URI<br> > > > character). Xerces (by default) will fix up the<br> > > > system ID before it's<br> > > > used. However, if you want your documents to be<br> > > > portable across different<br> > > > XML parsers, then you need to make sure that<br> > URIs<br> > > > you specify actually<br> > > > meet the URI spec.<br> > > ><br> > > > Hope that helps.<br> > > ><br> > > > -----------------------------------------<br> > > > Michael Glavassevich<br> > > > mrglavas@(protected)<br> > > > Candidate for Bachelor of Applied Science<br> > > > Computer Engineering<br> > > > University of Waterloo<br> > > ><br> > > > On Sat, 24 May 2003, Jon Wilmoth wrote:<br> > > ><br> > > > > I'm trying to parse a very simple xml document<br> > > > with<br> > > > > xerces 2.4.0. Unfortunately I get the<br> > following<br> > > > > error:<br> > > > ><br> > > > > java.net.MalformedURLException<br> > > > > at java.net.URL.<init>(URL.java:613)<br> > > > > at java.net.URL.<init>(URL.java:476)<br> > > > > at java.net.URL.<init>(URL.java:425)<br> > > > > at<br> > > > ><br> > > ><br> > ><br> ><br> org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown<br> > > > > Source)<br> > > > > at<br> > > > ><br> > > ><br> > ><br> ><br> org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown<br> > > > > Source)<br> > > > > at<br> > > > ><br> > > ><br> > ><br> ><br> org.apache.xerces.parsers.XML11Configuration.parse(Unknown<br> > > > > Source)<br> > > > > at<br> > > > ><br> > > ><br> > ><br> ><br> org.apache.xerces.parsers.DTDConfiguration.parse(Unknown<br> > > > > Source)<br> > > > > at<br> > > > ><br> > org.apache.xerces.parsers.XMLParser.parse(Unknown<br> > > > > Source)<br> > > > > at<br> > > > ><br> > > ><br> > ><br> ><br> org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown<br> > > > > Source)<br> > > > > at<br> > > > ><br> > > ><br> > org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)<br> > > > > at<br> > > > ><br> > > ><br> > org.jdom.input.SAXBuilder.build(SAXBuilder.java:673)<br> > > > ><br> > > > > The document:<br> > > > > <?xml version="1.0"?><br> > > > > <!DOCTYPE EventRegistrations SYSTEM<br> > > > ><br> > "<a href="file://C:\temp\projects\EventRegistrations.dtd" eudora="autourl" >file:///C:\temp\projects\EventRegistrations.dtd</a>"><br> > > > > <EventRegistrations><br> > > > > <x-tab> </x-tab><event<br> > > > name="test.events.BusinessObjectChangeEvent"><br> > > > > <x-tab> </x-tab><br> > <listener>test.ObjectCreationListener</listener><br> > > > > <x-tab> </x-tab></event> <br> > > > > </EventRegistrations><br> > > > ><br> > > > > Passes validation in my xml editor. What's<br> > going<br> > > > on?<br> > > > ><br> > ><br> > > __________________________________<br> > > Do you Yahoo!?<br> > > The New Yahoo! Search - Faster. Easier. Bingo.<br> > > <a href="http://search.yahoo.com/" eudora="autourl">http://search.yahoo.com</a> <br> > ><br> > ><br> ><br> ---------------------------------------------------------------------<br> > > To unsubscribe, e-mail:<br> > xerces-j-user-unsubscribe@(protected)<br> > > For additional commands, e-mail:<br> > xerces-j-user-help@(protected)<br> > ><br> > <br> ><br> ---------------------------------------------------------------------<br> > To unsubscribe, e-mail:<br> > xerces-j-user-unsubscribe@(protected)<br> > For additional commands, e-mail:<br> > xerces-j-user-help@(protected)<br> > <br><br> <br> __________________________________<br> Do you Yahoo!?<br> Yahoo! Calendar - Free online calendar with sync to Outlook(TM).<br> <a href="http://calendar.yahoo.com/" eudora="autourl">http://calendar.yahoo.com </a><br><br> ---------------------------------------------------------------------<br> To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected)<br> For additional commands, e-mail: xerces-j-user-help@(protected)</font></blockquote></body> </html>
|
|
 |