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.

2
  • Found it! Simply passing the variable to JSTL seems work fine. hah! didn't think it would! <% pageContext.setAttribute("xmldocument", strXmlDoc); %> Commented Dec 28, 2012 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 stackoverflow.com/questions/3177733/… Commented Dec 28, 2012 at 21:21

1 Answer 1

1

How about:

<c:set var="xmldocument"><books><book><name>Padam History</name><author>ZARA</author><price>100</price></book></books></c:set>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.