xtags v1.0 parse custom JSP tag using Dom4J Document object parameter
Background:
Trying to parse a Dom4J XML Document using <xtags:parse> in order to iterate through it (XSLT style) inside JSP code.
Problem Description:
The JSP code has an inline Dom4J Document object, however it cannot be passed as a parameter to xtags:parse
eg. when trying:
<%
org.dom4j.Document xmlDoc = ...;
%>
<xtags:parse reader="<%= xmlDoc %>" />
the following error message is occuring:
Explicit cast needed to convert org.dom4j.Document to java.io.Reader._jspx_th_xtags_parse_0.setReader( xmlDoc);
according to the xtags:parse v1.0 API documentation, this is occuring because the reader parameter of xtags:parse requires an object of type java.io.Reader so the question is how to get a java.io.Reader from an org.dom4j.Document (The xtags:parse v1.0 documentation shows how to parse a URL, an XML file, a java.io.Reader etc, but doesn't have an example for an org.dom4j.Document parameter).
Problem Solution:
Kind of straight-forward and ugly but:
<%
org.dom4j.Document xmlDoc = ...;
%>
<xtags:parse>
<%= xmlDoc.asXML() %>
</xtags:parse>
It would have been nicer to have a parameter to the tag that accepts an org.dom4j.Document however the performance doesn't seem to be an issue (ie. with the writing of the XML straight to the output stream).
Trying to parse a Dom4J XML Document using <xtags:parse> in order to iterate through it (XSLT style) inside JSP code.
Problem Description:
The JSP code has an inline Dom4J Document object, however it cannot be passed as a parameter to xtags:parse
eg. when trying:
<%
org.dom4j.Document xmlDoc = ...;
%>
<xtags:parse reader="<%= xmlDoc %>" />
the following error message is occuring:
Explicit cast needed to convert org.dom4j.Document to java.io.Reader._jspx_th_xtags_parse_0.setReader( xmlDoc);
according to the xtags:parse v1.0 API documentation, this is occuring because the reader parameter of xtags:parse requires an object of type java.io.Reader so the question is how to get a java.io.Reader from an org.dom4j.Document (The xtags:parse v1.0 documentation shows how to parse a URL, an XML file, a java.io.Reader etc, but doesn't have an example for an org.dom4j.Document parameter).
Problem Solution:
Kind of straight-forward and ugly but:
<%
org.dom4j.Document xmlDoc = ...;
%>
<xtags:parse>
<%= xmlDoc.asXML() %>
</xtags:parse>
It would have been nicer to have a parameter to the tag that accepts an org.dom4j.Document however the performance doesn't seem to be an issue (ie. with the writing of the XML straight to the output stream).













