How to get xml as response in struts2

Godly Chaos

New Member
I am trying to get a response in javascript of type xml in strurts2. In my action class I am creating a xml and I am trying to get it at java script. My code at action class -\[code\]public String populateXML(){ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder; String root = "menuTree"; File file = new File(this.getServletRequest().getRealPath("/xml/xmlmenutree2.xml")); documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document1 = documentBuilder.newDocument(); Element rootElement = null; rootElement = document1.createElement(root); document1.appendChild(rootElement); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(document1); StreamResult result = new StreamResult(file); transformer.transform(source, result); return SUCCESS;}\[/code\]This will create a xml file in my disk. and in my javascript i am accessing it like --\[code\]$(document).ready(function() { var options = { xmlUrl : 'xml/xmlmenutree2.xml' }; $('#xmlMenuTree').xmltree(options);}\[/code\]where xmlMenuTree is my div id at jsp.and strurts xml-\[code\]<action name="fileManagement" class="com.amit.MyAction" method="populateXML"> <result name="success" type="tiles">filemanagement</result></action>\[/code\]This is working fine. But I actually wanted the xml to be set at response instead of saving it in my disk.Is it possible to make a setup in strurts2? thank u in advance .Amit
 
Back
Top