0
votes

In a JSP page, using JSTL I can load an xml file, from xml file path or url to jstl variable as following:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<c:import url="my.xml" var="xmldocument"/>

Now, how do I do the exactly same thing if my xml file is in a String variable instead of the file system?

Say I have

<%
String strXmlDoc = "<books><book><name>Padam History</name><author>ZARA</author><price>100</price></book></books>";
%>

how do I import that to jstl var "xmldocument"?

Thanks.

1
Found it! Simply passing the variable to JSTL seems work fine. hah! didn't think it would! <% pageContext.setAttribute("xmldocument", strXmlDoc); %> - Will Robinson
You shouldn't mix scriptlets with taglibs/EL. The one is oldschool way of writing JSPs and the other is modern way of writing JSPs (well, modern.. it's done since almost a decade already.. imagine how oldschool those scriptlets are!). See also stackoverflow.com/questions/3177733/… - BalusC

1 Answers

1
votes

How about:

<c:set var="xmldocument"><books><book><name>Padam History</name><author>ZARA</author><price>100</price></book></books></c:set>