Ah. I thought
getClass().getResourceAsStream("test.xml") delegated
to the
getClass().getClassLoader().getResourceAsStream("test.xml")
and it was the location of the file (i.e.
com/acme/app/text.xml) that specified the package to
look under not the invoking class.
--- Jacob Kjome <[EMAIL PROTECTED]> wrote:
>
> 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
> ><[EMAIL 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
> > > [EMAIL 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
> > > > <[EMAIL 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
> > > > > [EMAIL 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:
> > > [EMAIL PROTECTED]
> > > > For additional commands, e-mail:
> > > [EMAIL PROTECTED]
> > > >
> > >
> > >
>
>---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > > [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> > > [EMAIL PROTECTED]
> > >
> >
> >
> >__________________________________
> >Do you Yahoo!?
> >Yahoo! Calendar - Free online calendar with sync to
> Outlook(TM).
> >http://calendar.yahoo.com
> >
>
>---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> >For additional commands, e-mail:
> [EMAIL PROTECTED]
>
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]