You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christian Rosenberger <pi...@gmx.de> on 2004/04/28 17:58:35 UTC

Cocoon, XML:DB and custom generator problem

Hello!

I have a problem with a custom generator executing XQuerys to a XML
database.

My result from database is:

<result>
<user><name>Test1</name></user>
<user><name>Test2</name></user>
</result>

The result is in a XMLResource instance.

Part of my custom generator code:

        //Execute query to XMLDB - done via XML:DB method (read is mapped to
XML:DB query method)
        ResourceSet result = xqm.read(xquery);
        XMLResource resource;

        //SAX Content Handler
        this.contentHandler.startDocument();
        for (long i = 0; i < result.getSize(); i++)
        {
                resource = (XMLResource)
                result.getResource(i);
                resource.getContentAsSAX(this.contentHandler);
        }
        this.contentHandler.endDocument();


So I have two results in my ResourceSet. (one for each user). I am browsing
these results and for each XMLResource in the ResourceSet I call the
getContentAsSax method.

The result is a nonvalid XML document with two <?xml..> tags:

<?xml version="1.0" encoding="ISO-8859-1"?>
<result><user> ... <?xml version="1.0" encoding="ISO-8859-1"?>
<result><user> ...

I tried to use the getContent method of the Resource interface, but I have
to set my content for SAX processing of Cocoon, so i cannot use Strings.

Any ideas what is going wrong in my Java code? Tried to call the
startElement method after calling the startDocument, but have also no
success with it!

Thanks in advance.

Regards,
Christian


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


Re: Cocoon, XML:DB and custom generator problem

Posted by Joerg Heinicke <jo...@gmx.de>.
On 28.04.2004 17:58, Christian Rosenberger wrote:

> The result is in a XMLResource instance.
> 
> Part of my custom generator code:
> 
>         this.contentHandler.startDocument();
>         for (long i = 0; i < result.getSize(); i++)
>         {
>                 resource = (XMLResource)
>                 result.getResource(i);
>                 resource.getContentAsSAX(this.contentHandler);
>         }
>         this.contentHandler.endDocument();
> 
> 
> So I have two results in my ResourceSet. (one for each user). I am browsing
> these results and for each XMLResource in the ResourceSet I call the
> getContentAsSax method.
> 
> The result is a nonvalid XML document with two <?xml..> tags:

Is only the XML declaration the problem or are there more, e.g. multiple 
root elements?

> Any ideas what is going wrong in my Java code? Tried to call the
> startElement method after calling the startDocument, but have also no
> success with it!

Don't understand the last sentence.

You might need to put another ContentHandler into the pipe that just 
ignores startDocument() and endDocument():

ContentHandler myContentHandler = new MyContentHandler(this.contentHandler);
this.contentHandler.startDocument();
for (long i = 0; i < result.getSize(); i++)
{
     resource = (XMLResource)
     result.getResource(i);
     resource.getContentAsSAX(myContentHandler);
}
this.contentHandler.endDocument();



private class MyContentHandler implements ContentHandler {

     private ContentHandler ch;

     MyContentHandler(ContentHandler ch) {
         this.ch = ch;
     }

     startDocument() {
         //ignore
     }

     endDocument() {
         //ignore
     }

     allOtherMethodsFromContentHandler() {
         this.ch.allOtherMethodsFromContentHandler();
     }
}

Joerg

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