xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dane Foster" <dfos...@equitytg.com>
Subject Re: XMLReader.parse
Date Fri, 22 Sep 2000 16:21:56 GMT
Before I start let me just say I don't know anything about the saxon API.  I
kinda glanced over their website but didn't go into much detail.  Anyway, I
think what I'm about to tell  you should work regardless, thanx to the power
of polymorphism.  Here we go:

If saxon simply sits on top of any SAX compliant parser then you should be
able to pass to the parse() method any object that is/or extends the
InputSource class.  With that in mind, all you should have to do is
something like this:

//This is a code snippet

 import java.io.*;            // This is new
 import org.xml.sax.*;
> import com.icl.saxon.ParserManager;
> import com.icl.saxon.ExtendedInputSource;
>
> XMLQueryFilter filt = new XMLQueryFilter(
(Parser)ParserManager.makeParser() );
>
> filt.setDocumentHandler( new XMLOutputter( sw ) );
>
/* My changes start here */
> filt.parse(  new InputSource( new StringReader( xml ) ) );    // Option 1
   filt.parse( new InputSource( new ByteArrayInputStream(
xml.getBytes() ) ) )    // Option 2

/* My changes end here.  NOTE:  If the original class that you had
(ExtendedInputStream) inherited from InputSource then it should still work
*/

// ..... rest of the code goes here

I hope that helped.


Dane

P.S   Just out of curiousity why are you using saxon.  Doesn't Xerces-J
provide all the functionality that you need?  If not, what is it lacking?


----- Original Message -----
From: "Michael Labhard" <mlabhard@viatraining.com>
To: <general@xml.apache.org>
Sent: Friday, September 22, 2000 11:02 AM
Subject: Re: XMLReader.parse


> To clarify:
>
> I have a class that imports the following
> ...
> import org.xml.sax.*;
> import com.icl.saxon.ParserManager;
> import com.icl.saxon.ExtendedInputSource;
>
> and I have a method that at some point makes the following calls:
> ...
>
> XMLQueryFilter filt = new XMLQueryFilter(
(Parser)ParserManager.makeParser() );
>
> filt.setDocumentHandler( new XMLOutputter( sw ) );
>
> filt.parse( new ExtendedInputSource(xml) );
>
> ...
>
> To explain these objects see:
>
> public class XMLQueryFilter extends ParserFilter
> {
> ...
>
> public abstract class ParserFilter
> implements Parser, AttributeList,
> DocumentHandler, DTDHandler, EntityResolver, ErrorHandler {
> ...
>
> I was hoping that the call "filt.parse(..." would be resolved to the
> Parser.parse( InputSource i ) method but it is not.  It is being resolved
to
> Parser.parse( java.lang.String systemid ) method instead.  Since "xml" is
a
> string containing XML and not a file path an error occurs of course.  How
do I
> encourage it to find the other method?  The method is present in the
SAXDriver
> of saxon.  Thanks.
>
>
> > I want to call SAXParser.parse( InputSource i ) because the SAXParser
> > implements XMLReader but whenever I make this call the call is resolved
to
> > SAXParser.parse( URL i ).  I have tried both the saxon and the xerces
> > SAXParser's.  My need is to provide the xml document as a character
stream, not
> > as a file.  Any help?  Thanks.
>
> ---------------------------------------------------------------------
> In case of troubles, e-mail:     webmaster@xml.apache.org
> To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
> For additional commands, e-mail: general-help@xml.apache.org
>
>


Mime
View raw message