cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Green" <>
Subject Re: Embedding XML results in an XSP page(might respond to "PI problem")
Date Wed, 11 Oct 2000 21:54:18 GMT
YP <> wrote:
>I felt difficult to embed computed XML in a XSP page.
>1) Direct text insertion does not work:
><xsp:logic> String xmlStr = new String ("<Hello> hello world </Hello>"
>); </xsp:logic>
><xsp:expr> xmlStr </xsp:expr>
>Produces a text node that contains "&lt;Hello&gt; hello world
>&lt;/Hello&gt;" that is not processed by XSLT.

Yes. It works exactly as the documentation says it should - converting a 
String to a Text node. I noticed the documentation doesn't mention that 
Nodes are left as-is (or cloned) - I've made that explicit now.

>This might be the response to Monica in "PI problem" message.

No, that's completely different.

>2) The following method works:
>     <!-- Proper imports are expected -->
>    <xsp:logic>
>         <![CDATA[
>	String xmlStr = new String ("<Hello> hello world </Hello>" )
>	Reader reader  = new StringReader(xmlStr);
>	InputSource    inputSource = new InputSource(reader);
>	Document doc = xspParser.parse(inputSource);
>	]]>
>   </xsp:logic>
>   <!-- The result is inserted this way -->
>   <xsp:expr> doc.getFirstChild() </xsp:expr>

There is a much easier way which I recently (re)discovered:


(obviously that example is pointless but it's just an example.)

As always you need to declare the util namespace in xsp:page.

>I do not understand exactly why "<xsp:expr> doc </xsp:expr>" fails.
>There is an issue with the document owner that causes a null pointer
>exception in Xerces.

In DOM, you cannot literally insert documents into documents. Document nodes 
are special containers for elements which cannot themselves have parents. 
Hence the error.

>As I have not found other method, I would appreciate all this stuff
>being handled automatically by the XSP processor. For example, extending
>the <xsp:expr> tag in such a way:
>     <xsp:expr type="xmlstring"> xmlStr </xsp:expr>
>The attribute "type" being used to direct the XSP to parse the string.

Well there is the util tag - if you want to make improvements go ahead, but 
I am satisfied with it.

>In addition, It is also possible to build a Document Object using the
>DOM API and to insert it in the XSP page using the <xsp:exp> tag (a
>thread can be open on this subject).

No. Another reason why is that you should not insert processing instructions 
into the middle of a document - only at the top. Therefore it's not a good 
idea, IMO, to insert documents into documents.

Get Your Private, Free E-mail from MSN Hotmail at

Share information about yourself, create your own public profile at

View raw message