You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Lars Huttar <la...@sil.org> on 2003/11/14 19:38:26 UTC

Re: Writing to filesystem

Hi all,
The following was discussed back in July:


>    * From: Ali Mesbah
>    * Subject: Re: Writing to filesystem
>    * Date: Mon, 16 Jun 2003 05:54:12 -0700 
> 
> As quoted from Geoff Howard <[EMAIL PROTECTED]>:
> > It is complaining about the whitespace nodes between source:frament and 
> > title.
> > You'll get this anytime you overwrite a whole document.  To fix, just do 
> > something like:
> > 
> > ...
> >   <source:fragment><title>SourceWritingTransformer Test Result 
> > 1</title></source:fragment>
> > ...
> 
> Wonderful. Thanks it works :) 
> 
> 
> > At 08:39 AM 6/16/2003, you wrote:
> > >As quoted from Upayavira <[EMAIL PROTECTED]>:
> > >> > Hi,
> > >> >
> > >> > What is the best way to write the output of a Transformer (in a
> > >> > pipeline) into a file (e.g. /resources/bla.xml) on the filesystem?
> > >>
> > >> Check out the SourceWritingTransformer.
> > >
> > >I am checking it out. thanks. I'm getting an error though:
> > >
> > >failedThere was a problem manipulating your document: 
> > >org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to 
> > >insert a node where it is not permitted. 
> > >writenonefile:/resources/result.xml
> > >
> > >
> > >My xml source (called test.xml):
> > ><?xml version="1.0" encoding="UTF-8"?>
> > ><page>
> > ><source:write xmlns:source="http://apache.org/cocoon/source/1.0";>
> > >  <source:source>context://resources/result.xml</source:source>
> > >  <source:fragment>
> > >    <title>SourceWritingTransformer Test Result 1</title>
> > >  </source:fragment>
> > ></source:write>
> > ></page>
> > 

My problem is, the source fragment to be written out is
a text string, generated using a series of <xsl:text>
and <xsl:value-of> elements:
      <source:fragment>
          <xsl:text>-- SQL Server 2000 database schema for </xsl:text>
          <xsl:value-of select="system"/>
		...

Even if I eliminate space between <source:fragment> and <xsl:text>,
the same error still occurs.
However if I wrap the text items in a dummy element:
      <source:fragment>
        <dummy>
          <xsl:text>-- SQL Server 2000 database schema for </xsl:text>
          <xsl:value-of select="system"/>
		...
	   </dummy>
      </source:fragment>

the error goes away.
Presumably it's complaining because the content of <source:fragment>
is just that, an XML fragment, rather than a proper XML document
with one top-level node.
But how can that be? Surely you can write text files using
SourceWritingTransformer, not just XML documents.

Besides, it used to work... I have a copy of the file from 10 days ago
that was written out by this same pipeline. And I can't figure out
what might have changed.

Based on what Geoff said about overwriting, I tried deleting
the old file first in case that helped. It didn't.

Thanks for any hints,
Lars


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


RE: Writing to filesystem

Posted by Lars Huttar <la...@sil.org>.
Upayavira wrote:
> Lars Huttar wrote:
> 
> >>Presumably it's complaining because the content of <source:fragment>
> >>is just that, an XML fragment, rather than a proper XML document
> >>with one top-level node.
> >>But how can that be? Surely you can write text files using
> >>SourceWritingTransformer, not just XML documents.
> >>    
> >>
> >
> >OK, my mistake. The docs at
> >http://cocoon.apache.org/2.1/userdocs/transformers/sourcewrit
> ing-transformer.html#The+Tags+in+detai
> >l
> >say you can only write an actual XML document.
> >Don't know why it worked before.
> >Guess we'll have to use some other mechanism.
> >
> >Lars
> >  
> >
> AFAIK, you can specify the serializer that you use before 
> writing back 
> to disk. The default (as you've seen) is the XML one.
> 
> Can't remember where you specify the serializer though.

Thanks.
That indeed turned out to be the trick, as we discovered
just now.
You use a dummy XML wrapper inside <source:fragement>,
e.g.

      <source:fragment>
        <dummy>
          <xsl:text>-- SQL Server 2000 database schema for </xsl:text>
          <xsl:value-of select="system"/>
		...
	   </dummy>
      </source:fragment>

and then in the sitemap you specify the text serializer using
a parameter:
      <map:transform type="write-source">
          <map:parameter name="serializer" value="text"/>
      </map:transform>
      <map:serialize/>

Of course, this only works for text-only data;
if your data is truly an XML fragment, serializing it as
text will mean you lose all your tags.

Lars


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


Re: Writing to filesystem

Posted by Upayavira <uv...@upaya.co.uk>.
Lars Huttar wrote:

>>Presumably it's complaining because the content of <source:fragment>
>>is just that, an XML fragment, rather than a proper XML document
>>with one top-level node.
>>But how can that be? Surely you can write text files using
>>SourceWritingTransformer, not just XML documents.
>>    
>>
>
>OK, my mistake. The docs at
>http://cocoon.apache.org/2.1/userdocs/transformers/sourcewriting-transformer.html#The+Tags+in+detai
>l
>say you can only write an actual XML document.
>Don't know why it worked before.
>Guess we'll have to use some other mechanism.
>
>Lars
>  
>
AFAIK, you can specify the serializer that you use before writing back 
to disk. The default (as you've seen) is the XML one.

Can't remember where you specify the serializer though.

Regards, Upayavira



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


RE: Writing to filesystem

Posted by Lars Huttar <la...@sil.org>.
> > Presumably it's complaining because the content of <source:fragment>
> > is just that, an XML fragment, rather than a proper XML document
> > with one top-level node.
> > But how can that be? Surely you can write text files using
> > SourceWritingTransformer, not just XML documents.
> 
> OK, my mistake. The docs at
> http://cocoon.apache.org/2.1/userdocs/transformers/sourcewriti
> ng-transformer.html#The+Tags+in+detai
> l
> say you can only write an actual XML document.
> Don't know why it worked before.
> Guess we'll have to use some other mechanism.

So... can anybody tell me how to write arbitrary text (coming along
a pipeline wrapped in XML) to a file (minus the XML wrapper), in Cocoon?
Thanks much!

Lars


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


RE: Writing to filesystem

Posted by Lars Huttar <la...@sil.org>.
> Presumably it's complaining because the content of <source:fragment>
> is just that, an XML fragment, rather than a proper XML document
> with one top-level node.
> But how can that be? Surely you can write text files using
> SourceWritingTransformer, not just XML documents.

OK, my mistake. The docs at
http://cocoon.apache.org/2.1/userdocs/transformers/sourcewriting-transformer.html#The+Tags+in+detai
l
say you can only write an actual XML document.
Don't know why it worked before.
Guess we'll have to use some other mechanism.

Lars


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