You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "JACOB, ERIC" <er...@bell.ca> on 2004/10/01 15:03:53 UTC

XMLReader question

Hi,

I use the XMLReader class into a custom transformer to parse an XML string
like the following:

this.sendStartElementEvent( ROOT_ELEMENT );

XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler( super.xmlConsumer );
InputSource source = new InputSource( new StringReader( xmlString ) );
xmlReader.parse( source );

this.sendEndElementEvent( ROOT_ELEMENT );

That works fine, but the output contains an undesired XML declaration:

<root>
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <message>
    ...
  </message>
</root>

How I could avoid this?

Thanks,

Eric

-----Original Message-----
From: JACOB, ERIC [mailto:eric.jacob@bell.ca] 
Sent: Wednesday, September 29, 2004 11:35 AM
To: users@cocoon.apache.org
Subject: Parse an xml string inside a transformer

Hi,

I'm wondering how to parse an xml string inside a transformer.

this.sendStartElementEvent( ROOT_ELEMENT );
// here the xml string that I want to parse...
this.sendEndElementEvent( ROOT_ELEMENT );

Thanks,

Eric




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: XMLReader question

Posted by Joerg Heinicke <jo...@gmx.de>.
On 01.10.2004 15:03, JACOB, ERIC wrote:
> Hi,
> 
> I use the XMLReader class into a custom transformer to parse an XML string
> like the following:
> 
> this.sendStartElementEvent( ROOT_ELEMENT );
> 
> XMLReader xmlReader = XMLReaderFactory.createXMLReader();
> xmlReader.setContentHandler( super.xmlConsumer );
> InputSource source = new InputSource( new StringReader( xmlString ) );
> xmlReader.parse( source );
> 
> this.sendEndElementEvent( ROOT_ELEMENT );
> 
> That works fine, but the output contains an undesired XML declaration:
> 
> <root>
>   <?xml version="1.0" encoding="ISO-8859-1"?>
>   <message>
>     ...
>   </message>
> </root>
> 
> How I could avoid this?

The content handler set on the XMLReader object must filter out 
startDocument and endDocument event by an empty implementation of both.

Joerg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org