You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Laurent Eskenazi <le...@mail.inforama.fr> on 2000/02/02 19:14:36 UTC

Generated XML formating

Hi!

I've got a problem with java generated XML included in a XML file.
I've got a class which can describe itself in XML, and I'd like to have it
included in XML files and the result XML parsed with XSLT.
My problem is that every "<" or ">" is being replaced by a "&lt;" or "&gt;",
and so, the result string isn't parsed with XSLT as I expected. I tried to
use the <!CDATA[[]]> trick, but it was no use.

Does anybody know how to do such a thing ?

Thanks per advance.

Laurent

Here are some code samples to understand the problem:


Foo.java:

class Foo
{
String toString()
    {
        String tmp=new String();
        tmp+="<foo>";
        tmp+="<bar>";
        tmp+="xyzABCD";
        tmp+="</bar>";
        tmp+="</foo>;
    }
}



Foo.xml:

<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<xsp:page language="java" xmlns:xsp=http://www.apache.org/1999/XSP/Core>
<xsp:structure>
 <xsp:include>Foo</xsp:include>
</xsp:structure>
<xsp:logic>Foo foo=new Foo();</xsp:logic>
<page>
<xsp:expr>foo</xsp:expr>
<!-- I'd like the XML code to be included here using the toString()
ethod  -->
</page>
</xsp:page>



Foo.xsl:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="page">
<html>
<body bgcolor="#ffffff"><font face="Verdana, Arial, Helvetica, sans-serif">
<xsl:apply-templates/>
</font></body>
</html>
</xsl:template>

<xsl:template match="event">
<p><font size="1"><xsl:value-of select="bar"></p>
</xsl:template>

</xsl:stylesheet>




Re: Generated XML formating

Posted by Mike Engelhart <me...@earthtrip.com>.
Laurent Eskenazi wrote:

> 
> You mean I have to replace every "<" and ">" by "&lt;" and "&gt;" in my Java
> code ?
> I'd really like to stay with "<" and ">",  so how to I have to use a DTD ?
Yup.  I can't explain how to use a DTD on an email list.  it's way out of
scope.  There are several 1000+ page books on how to write these things.  Of
course simple ones are pretty straighforward but I'm really not an expert.
Check out:

http://www.w3.org

and look around in the XML section for pointers.  I'd go out and get an XML
book too (if you can find a good one :-()

Mike


Re: Generated XML formating

Posted by Laurent Eskenazi <le...@mail.inforama.fr>.
> Laurent Eskenazi wrote:
>
> > Hi!
> >
> > I've got a problem with java generated XML included in a XML file.
> > I've got a class which can describe itself in XML, and I'd like to have
it
> > included in XML files and the result XML parsed with XSLT.
> > My problem is that every "<" or ">" is being replaced by a "&lt;" or
"&gt;",
> > and so, the result string isn't parsed with XSLT as I expected. I tried
to
> > use the <!CDATA[[]]> trick, but it was no use.
> >
> > Does anybody know how to do such a thing ?
> >
> > Thanks per advance.
> >
> > Laurent
> You have to explicitly use the &lt; or &gt; entities unless you use a DTD
to
> describe what < and > mean.

You mean I have to replace every "<" and ">" by "&lt;" and "&gt;" in my Java
code ?
I'd really like to stay with "<" and ">",  so how to I have to use a DTD ?

> Change your code to use these.   BTW, if you're going to manually create
> Strings of XML, I'd recommend getting the Element Construction Set from
> java.apache.org.  It allows you to create XML elements using objects
rather
> than strings and is much more error free....

Ok, I'll have a look at it.

Thnaks for your help.

Laurent



Re: Generated XML formating

Posted by Mike Engelhart <me...@earthtrip.com>.
Laurent Eskenazi wrote:

> Hi!
> 
> I've got a problem with java generated XML included in a XML file.
> I've got a class which can describe itself in XML, and I'd like to have it
> included in XML files and the result XML parsed with XSLT.
> My problem is that every "<" or ">" is being replaced by a "&lt;" or "&gt;",
> and so, the result string isn't parsed with XSLT as I expected. I tried to
> use the <!CDATA[[]]> trick, but it was no use.
> 
> Does anybody know how to do such a thing ?
> 
> Thanks per advance.
> 
> Laurent
You have to explicitly use the &lt; or &gt; entities unless you use a DTD to
describe what < and > mean.

Change your code to use these.   BTW, if you're going to manually create
Strings of XML, I'd recommend getting the Element Construction Set from
java.apache.org.  It allows you to create XML elements using objects rather
than strings and is much more error free....

mike