My Application is using XForms for view and XForms generate output XML containing the answer given by user. If we include the following 开发者_如何学Cline
<fr:xforms-inspector xmlns:fr="http://orbeon.org/oxf/xml/form-runner"/>
in the code we can see the generated output in the screen. So for username if user type amit
it would also come with the generated XML.
I actually wanted to get this generated XML in my Java Class to save it in database and parse it and split its contents. I have tried the following code for getting that XML but not able to get the generated XML.
BufferedReader requestData = new BufferedReader(new InputStreamReader(request.getInputStream()));
StringBuffer stringBuffer = new StringBuffer();
String line;
try{
while ((line = requestData.readLine()) != null) {
stringBuffer.append(line);
}
} catch (Exception e){}
return stringBuffer.toString();
}
Please let me know what wrong I am doing.
Assuming that you'd like to have Java code inside a servlet or JSP that receives XML posted to the servlet or JSP through an XForms submission, then I would recommend you parse it using an XML parser rather than doing this by hand. Doing this with Dom4j is quite simple; for instance to get the content of the root element (assuming that all you receive is an element with some text in it):
Document queryDocument = xmlReader.read(request.getInputStream());
String query = queryDocument.getRootElement().getStringValue();
And for reference, see the full source of an example this is taken from.
精彩评论