0

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.

Will Robinson
  • 631
  • 2
  • 6
  • 11
  • Found it! Simply passing the variable to JSTL seems work fine. hah! didn't think it would! <% pageContext.setAttribute("xmldocument", strXmlDoc); %> – Will Robinson Dec 28 '12 at 20:16
  • 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 http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202 – BalusC Dec 28 '12 at 21:21

1 Answers1

1

How about:

<c:set var="xmldocument"><books><book><name>Padam History</name><author>ZARA</author><price>100</price></book></books></c:set>
kschneid
  • 5,626
  • 23
  • 31