You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Michael Labhard <ml...@viatraining.com> on 2000/09/22 01:53:38 UTC

XMLReader.parse

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.


Re: XMLReader.parse

Posted by Dane Foster <df...@equitytg.com>.
I'm a little unclear on what you are trying to do.  Please re-word.
----- Original Message -----
From: "Michael Labhard" <ml...@viatraining.com>
To: "XML General" <ge...@xml.apache.org>
Sent: Thursday, September 21, 2000 7:53 PM
Subject: XMLReader.parse


> 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
>
>


Re: XMLReader.parse

Posted by Michael Labhard <ml...@viatraining.com>.
> 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?

Namespace alias.  We can provide example code if you like.


Re: XMLReader.parse

Posted by Dane Foster <df...@equitytg.com>.
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" <ml...@viatraining.com>
To: <ge...@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
>
>


Re: XMLReader.parse

Posted by Michael Labhard <ml...@viatraining.com>.
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.

Re: XMLReader.parse

Posted by Michael Labhard <ml...@viatraining.com>.
	Sorry.  It IS finding the Parser.parse( InputSource i ) method, but
this method still requires a "systemid" that must resolve to a URI.  Can anyone
provide me with an example of SAX parsing of a character stream and not a URI? 
Thanks.


Re: XMLReader.parse

Posted by Michael Labhard <ml...@viatraining.com>.
Got it!  Had to explicitly assign the string to the InputSource's character
stream:

		ExtendedInputSource eis = new ExtendedInputSource();
		eis.setCharacterStream(new StringReader(xml));
		filt.parse( eiS );

Thanks for your attention.  Sometimes just talking is all you need.