[SoapRMI] problem with setInput [Re: XPP3]

Aleksander Slominski aslom_at_cs.indiana.edu
Wed, 08 May 2002 04:26:31 -0500


Andrew Keidel wrote:

> I like your xpp product a lot,

:-)

> but am having an odd problem using it.

not good ...

> The
> parsing works fine when I give it an input string, but fails to work
> properly when I use it on an InputStream from a File.
>
> Here is the code I'm using:
>
> File f = new File("C:\\\\test\\sample.xml");
> FileInputStream fis = new FileInputStream(f);
> XmlTestCreator xmlTestCreator = new XmlTestCreator();
> xmlTestCreator.setInput(new InputStreamReader(new
> NoBufferingInputStream(fis)));
> test = xmlTestCreator.processDocument();
> xmlTestCreator.setInput(null);

nothing obviously wrong here except that use of NoBufferingInputStream
may degrade perfromance :-)

> I've tried *several* approaches for reading from a file into the parser, but
> the only one that works is when I do something like the following:
>
> xmlTestCreator.setInput(new StringReader(myString));
>
> where myString is a string containing the entire xml text.  The problem with
> this approach is that it will perform poorly when the xml document is huge
> (which will require myString to be an enormous string).
>
> I haven't tried using sockets yet... I believe that part will work.  But I
> want to be able to read xml from a file.
>
> Suggestions?

did you look on src/java/samples/MyXmlPullApp.java in XPP3 distribution.

for example running it on build.xml produces this (make sure you get the same parser implementation
class!):

     java MyXmlPullApp build.xml
     parser implementation class is class org.xmlpull.mxp1.MXParserCachingStrings
     Parsing file: build.xml
     Start document
     Start element: project
     Characters:    "\n\n  \n  \n\n  "
     Start element: property
     End element: property
     Characters:    "\n\n  "
     Start element: property
     End element: property
     Characters:    "\n  "
     ...

all what this sample does to set input is to call
   xpp.setInput ( new FileReader ( args [i] ) ).

then i modified sample to use:
      xpp.setInput ( new InputStreamReader( new FileInputStream ( args [i] ) ) );
and it worked also fine.

finally i have used new method setInput that takes input stream directly:
  xpp.setInput ( new FileInputStream ( args [i] ), "UTF8"  );
and that also worked :-)

please make sure that you use the latast XPP3 version 1.0.8a from
    http://www.extreme.indiana.edu/xgws/xsoap/xpp/download/

using StringReader is discouraged as it will prevent from doing
real incremental (streaming) file parsing.

hope it helps (let me know if you still have problem),

thanks.

alek