xerces-j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Randy Cox" <randy....@countrycompanies.com>
Subject Re: Problem parsing from a string.
Date Mon, 16 Oct 2000 14:22:35 GMT
That solved the problem.

Thank you very much for the help.

Randy Cox
----- Original Message -----
From: "Jeffrey Rodriguez" <jeffreyr_97@hotmail.com>
To: <randy.cox@countrycompanies.com>; <xerces-j-dev@xml.apache.org>
Sent: Friday, October 13, 2000 12:24 PM
Subject: Re: Problem parsing from a string.


> Hi Randy,
>
> Sorry for not getting back to you because of time constraints.
>
> The good news is that I was able to reproduce your problem and I
> have a solution for you.
>
> The reason for getting the nullpointer is because our entity resolver
cannot
> find the dtd.
>
> You need to specify a SystemId ( though documentation say that you may! )
> but since we are defining an InputSource based on a reader then the
default
> can not resolve a relative URL ( e.g.
>   <!ENTITY % msg-body-entity SYSTEM "ListOfSmallContact.dtd">
> ). It seems like the defaul SystemId is null since we are not really
> reading from a file but a String.
> Well the work around is just to define the SystemID by calling the
> InputSource setSystemId method.
> Set SystemId to the url to use as a relative place from where to find
> relative URI.
>
>
> e.g.
>
> String xmlFile            = "c:\\bug\\cox.xml";
>       String xmlData            = null;
>       try {
>          FileInputStream fin = new FileInputStream( xmlFile );
>          ByteArrayOutputStream  bo  = new ByteArrayOutputStream();
>          int   data;
>          while ( ( data = fin.read() ) != -1 ) {
>             bo.write(data);
>          }
>          xmlData             = bo.toString();
>          Reader       reader = new BufferedReader( new StringReader(
xmlData
> ) );
>          InputSource  source = new InputSource( reader );
>
>          source.setSystemId("file:///c:/bug/");// You need this otherwise
> get nullpointer
>
>          DOMParser    parser = new DOMParser();
>          //SAXParser    parser = new SAXParser();
>          parser.setErrorHandler( new test() );
>          parser.setFeature( "http://xml.org/sax/features/validation", true
> );
>          parser.parse(source);
>          Document doc = parser.getDocument();
>
>          System.out.println( "doc = " + doc );
>
> Hope this helps,
>
>                    Jeffrey Rodriguez
>                    IBM Silicon Valley
>                    XML Development
>
>
> >From: "Randy Cox" <randy.cox@countrycompanies.com>
> >Reply-To: "Randy Cox" <randy.cox@countrycompanies.com>
> >To: "Jeffrey Rodriguez" <jeffreyr_97@hotmail.com>
> >Subject: Re: Problem parsing from a string.
> >Date: Fri, 13 Oct 2000 09:09:14 -0500
> >
> >Jeffrey
> >
> >Did you get my first response? (copied below)  Did it give you any
insight
> >or do you need any more information?
> >
> >Randy Cox
> >randy.cox@countrycompanies.com
> > >>>>>>>>
> >Jeffrey
> >
> >Yes that is the problem I am having.
> >
> >What I am doing is I get the xml in as a string and do:
> >try {
> >   Reader reader = new BufferedReader(new StringReader(xmlString));
> >   InputSource source = new InputSource(reader);
> >   DOMParser parser = new DOMParser();
> >  }
> >catch ( )
> >
> >and get the null parm exception.
> >
> >This is not a problem with sample xml documents but with the case I
> >attached
> >to my first mail:
> >
> > >>>>
> ><!DOCTYPE Message [
> >   <!ELEMENT Message (ListOfSmallContact)>
> >   <!ATTLIST Message
> >   MessageId CDATA #REQUIRED
> >     MessageType CDATA #REQUIRED
> >     IntObjectName CDATA #REQUIRED
> > >
> >   <!ENTITY % msg-body-entity SYSTEM "ListOfSmallContact.dtd">
> >   %msg-body-entity;
> >]>
> > >>>
> >
> >I believe the problem in with the external entity line.
> >
> >If I change the DOCTYPE statement to:
> >
> > >>>>
> ><!DOCTYPE Message SYSTEM "ListOfSmallContact.dtd" [
> >   <!ELEMENT Message (ListOfSmallContact)>
> >   <!ATTLIST Message
> >   MessageId CDATA #REQUIRED
> >     MessageType CDATA #REQUIRED
> >     IntObjectName CDATA #REQUIRED
> >   >
> >   ]>
> >
> > >>>>
> >The exception goes away.  However, I don't have control of the xml or the
> >dtd that I am receiving.
> >
> >Randy
> >
> >
> >
> > >>>>>>>>
> >----- Original Message -----
> >From: "Jeffrey Rodriguez" <jeffreyr_97@hotmail.com>
> >To: <xerces-j-dev@xml.apache.org>
> >Sent: Thursday, October 05, 2000 11:24 AM
> >Subject: Re: Problem parsing from a string.
> >
> >
> > > Hi Randy,
> > >
> > >
> > > >>I have the following xml and dtd.  If if call the paser passing in
a
> > >>uri
> > > >>to the xml file I can parse the file with no problem.  If I try to
> > >
> > > So you are doing something like:
> > >
> > > try {
> > >     parser.parse( "file:....." );
> > >      .
> > >      .
> > >    } catch( ......
> > >
> > > This works right?
> > >
> > > Now for your string you are using an InputStream so you are doing
> >something
> > > like:
> > >
> > > StringReader input = new StringReader( message );//message is your XML
> > > string
> > >
> > > InputSource messSource = new InputSource( input );
> > > .
> > > .
> > > .
> > > .
> > >
> > > try {
> > >     parser.parse( messSource );
> > >      .
> > >      .
> > >    } catch( ......
> > >
> > > right? You said that this does not work, you get a nullpointer
> >exception?
> > >
> > > I wrote a very simple testcase that works fine using a string.
> > >
> > > Please send me more details.
> > >
> > > Thanks for reporting this,
> > >
> > >                              Jeffrey Rodriguez
> > >                              Xerces-J Developer
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >_________________________________________________________________________
> > > Get Your Private, Free E-mail from MSN Hotmail at
> >http://www.hotmail.com.
> > >
> > > Share information about yourself, create your own public profile at
> > > http://profiles.msn.com.
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> > > For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
> >
>
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
> Share information about yourself, create your own public profile at
> http://profiles.msn.com.


Mime
View raw message