You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Justin Fagnani-Bell <ju...@paraliansoftware.com> on 2002/08/08 23:38:39 UTC

Keeping HTMLSerializer from altering markup?

Hi list,

  I have a page with a form generated by Cocoon. There's a textarea in 
the form where you can edit some xml (possibly xhtml). Because the form 
is an HTML form I'm using an HTMLSerializer. But I want to keep the 
serializer from altering the markup in the textarea, because if it's 
xhtml content it will turn <br/>'s into <br>'s. Then when the text is 
saved and you visit the form again, or view the page the text is on, I 
get a parsing error.

My xml fil looks somethng like this:

<node name="test" title="Test">
   <text name="content">
     <p>
       Here's some text that will get messed up by HTMLSerializer
       <br/>
       Then I'll get an error.
     </p>
   </text>
</node>

I use an xslt template to turn this into my form that looks likt this:

<xsl:template match="text>
   <textarea name="@name"><xsl:copy-of select="* | text()"/></textarea>
</xsl:template>

I've tried a few things with no luck so far. I added a 
xmlns="http://www.w3.org/1999/xhtml" attribute to the text element 
hoping that HTMLSerializer would then leave it alone, but my stylesheet 
won't copy the text now. I tried copying the xml serializer component in 
<map:serializers>, renaming it "xhtml" and changing the mime-type to 
text/html, but the browser wouldn't render it.

(Along a similar line, I was trying to use jTidy to turn html into 
xhtml, in case the user didn't enter well-formed xml. But I'm dealing 
with html fragments and jTidy kept wraping everything in <html><body>, 
etc...)

Any ideas?

Thanks,
   Justin


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: Keeping HTMLSerializer from altering markup?

Posted by Joerg Heinicke <jo...@gmx.de>.
KOZLOV Roman wrote:
 > Hi,
 >
 > Just a question, if XHTML is XML then is it possible to use XML serializer?
 > If not, why?
 >
 > Roman

Yes, it's possible of course. When serializing a document as XHTML instead 
of XML, the doctype declaration for XHTML will be added.

Regards,

Joerg

-- 

System Development
VIRBUS AG
Fon  +49(0)341-979-7419
Fax  +49(0)341-979-7409
joerg.heinicke@virbus.de
www.virbus.de


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: Keeping HTMLSerializer from altering markup?

Posted by Justin Fagnani-Bell <ju...@paraliansoftware.com>.
Thanks for the replies guys, unfortunately I'm still kinda stuck.

I tried the xhtml serializer (which is really an xml serializer) and the 
xml serializer They almost work, but not quite. First, Mozilla 1.0 won't 
render tables correctly (<td> bgcolor attribute, though Chimera renders 
fine) for some reason. More importantly they turn an empty set of tags 
(ie. <textarea></textarea>) into one tag (<textarea/>) which is fine for 
most tags, but for textarea (in Mozilla at least) it causes the text 
field to be filled with the contents of the html file after the 
<textarea/> tag to the end of file.

I'm not sure whether <textarea/> is correct in XHTML. If it's not then 
this could probably be called a bug in an xhtml serializer, even though 
this makes sense in terms of xml. If it is correct (which i suspect) 
then it's a bug in Mozilla. Either way it's a PITA.

One solution might be to turn off combining empty tags in the xml 
serializer. Is there a way to do this? There's no docs on the 
cofiguration parameters for any of the serializers, and I'm a little 
confused by the source. It looks like XMLSerializer, and HTMLSerializer 
(through AbstractTextSerializer) get a transformer to do the conversion, 
and pass a bunch of parameters to it. I assume method is the xslt output 
method, but what is cdata-section-elements? Could it be of use to me 
here?

Another thing I tried was using a TextSerializer, with the mime-type set 
to text/html. I figured that for text output it wouldn't mess with the 
tags, only problem was that mozilla wouldn't render any of the tags, 
just the text. This is probably because of a namepsace or dtd issue and 
I'm gonna try to fix it.

Justin

oh yeah, on more thing that may be important. I'm using cocoon 2.0.1. It 
didn't include an xhtml entry in <map:serializers> so I copied it from 
2.0.3. If the serializers behave differently that could be an issue, but 
I don't think I can upgrade right now. I'll see.

On Friday, August 9, 2002, at 12:42 AM, KOZLOV Roman wrote:

> Hi,
>
> Just a question, if XHTML is XML then is it possible to use XML 
> serializer?
> If not, why?
>
> Roman
>
> Vadim Gritsenko wrote:
>
>>> From: Justin Fagnani-Bell [mailto:justin@paraliansoftware.com]
>>>
>>> Hi list,
>>>
>>>   I have a page with a form generated by Cocoon. There's a textarea in
>>> the form where you can edit some xml (possibly xhtml). Because the
>> form
>>> is an HTML form I'm using an HTMLSerializer. But I want to keep the
>>> serializer from altering the markup in the textarea, because if it's
>>> xhtml content it will turn <br/>'s into <br>'s. Then when the text is
>>> saved and you visit the form again, or view the page the text is on, I
>>> get a parsing error.

<snip>

>> Try xhtml serializer, it comes with default sitemap.
>>
>> Vadim
>>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: Keeping HTMLSerializer from altering markup?

Posted by KOZLOV Roman <r-...@opencascade.com>.
Hi,

Just a question, if XHTML is XML then is it possible to use XML serializer?
If not, why?

Roman

Vadim Gritsenko wrote:

> > From: Justin Fagnani-Bell [mailto:justin@paraliansoftware.com]
> >
> > Hi list,
> >
> >   I have a page with a form generated by Cocoon. There's a textarea in
> > the form where you can edit some xml (possibly xhtml). Because the
> form
> > is an HTML form I'm using an HTMLSerializer. But I want to keep the
> > serializer from altering the markup in the textarea, because if it's
> > xhtml content it will turn <br/>'s into <br>'s. Then when the text is
> > saved and you visit the form again, or view the page the text is on, I
> > get a parsing error.
> >
> > My xml fil looks somethng like this:
> >
> > <node name="test" title="Test">
> >    <text name="content">
> >      <p>
> >        Here's some text that will get messed up by HTMLSerializer
> >        <br/>
> >        Then I'll get an error.
> >      </p>
> >    </text>
> > </node>
> >
> > I use an xslt template to turn this into my form that looks likt this:
> >
> > <xsl:template match="text>
> >    <textarea name="@name"><xsl:copy-of select="* |
> text()"/></textarea>
> > </xsl:template>
> >
> > I've tried a few things with no luck so far. I added a
> > xmlns="http://www.w3.org/1999/xhtml" attribute to the text element
> > hoping that HTMLSerializer would then leave it alone, but my
> stylesheet
> > won't copy the text now.
>
> <xsl:template match="x:text" xmlns:x="http://www.w3.org/1999/xhtml">
>   <textarea name="@name"><xsl:copy-of select="* | text()"/></textarea>
> </xsl:template>
>
> But it won't help you.
>
> Try xhtml serializer, it comes with default sitemap.
>
> Vadim
>
> > I tried copying the xml serializer component in
> > <map:serializers>, renaming it "xhtml" and changing the mime-type to
> > text/html, but the browser wouldn't render it.
> >
> > (Along a similar line, I was trying to use jTidy to turn html into
> > xhtml, in case the user didn't enter well-formed xml. But I'm dealing
> > with html fragments and jTidy kept wraping everything in <html><body>,
> > etc...)
> >
> > Any ideas?
> >
> > Thanks,
> >    Justin
> =
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


RE: Keeping HTMLSerializer from altering markup?

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Justin Fagnani-Bell [mailto:justin@paraliansoftware.com]
> 
> Hi list,
> 
>   I have a page with a form generated by Cocoon. There's a textarea in
> the form where you can edit some xml (possibly xhtml). Because the
form
> is an HTML form I'm using an HTMLSerializer. But I want to keep the
> serializer from altering the markup in the textarea, because if it's
> xhtml content it will turn <br/>'s into <br>'s. Then when the text is
> saved and you visit the form again, or view the page the text is on, I
> get a parsing error.
> 
> My xml fil looks somethng like this:
> 
> <node name="test" title="Test">
>    <text name="content">
>      <p>
>        Here's some text that will get messed up by HTMLSerializer
>        <br/>
>        Then I'll get an error.
>      </p>
>    </text>
> </node>
> 
> I use an xslt template to turn this into my form that looks likt this:
> 
> <xsl:template match="text>
>    <textarea name="@name"><xsl:copy-of select="* |
text()"/></textarea>
> </xsl:template>
> 
> I've tried a few things with no luck so far. I added a
> xmlns="http://www.w3.org/1999/xhtml" attribute to the text element
> hoping that HTMLSerializer would then leave it alone, but my
stylesheet
> won't copy the text now.

<xsl:template match="x:text" xmlns:x="http://www.w3.org/1999/xhtml">
  <textarea name="@name"><xsl:copy-of select="* | text()"/></textarea>
</xsl:template>

But it won't help you.

Try xhtml serializer, it comes with default sitemap.


Vadim

> I tried copying the xml serializer component in
> <map:serializers>, renaming it "xhtml" and changing the mime-type to
> text/html, but the browser wouldn't render it.
> 
> (Along a similar line, I was trying to use jTidy to turn html into
> xhtml, in case the user didn't enter well-formed xml. But I'm dealing
> with html fragments and jTidy kept wraping everything in <html><body>,
> etc...)
> 
> Any ideas?
> 
> Thanks,
>    Justin
=


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>