PDA

View Full Version : Pass XML String from a JSP to JS


sandhya6
09-07-2009, 03:08 PM
A sample JSP of mine would have an XML string and I would like to pass that string to a JS function.

<html>
<%@ page language="java" %>
<%
String xml = "<?xml version='1.0' encoding='UTF-8'?><taf> <functionaltestcase> <component>Core</component> <name>Terminate</name> <description>Termination of Core bucket</description> <result>pass</result> <pass>1</pass> <fail>0</fail> <starttime>1245412716</starttime> <endtime>1245412716</endtime> <verification_type>webtest_log</verification_type> </functionaltestcase> </taf>";
%>
<head>
<head>
<title>JSP Page</title>
<script type="text/javascript">
function assign()
{

var xml1 = "<%=xml%>";
asjson(xml1);
return false;
}
function asjson(txt){

alert(txt);


}
</script>
</head>
<body>
<form name="xml2jsonform" method="post" action="javascript:void(0)" onSubmit="return assign()">
</form>
</body>
</html>

Could some one let me know how to pass the value of xml string to a Javascript function?

Thanks!