Jump to content

JSP to xml


Singh Soorma
 Share

Recommended Posts

Normally, any serverside page such as ASP,PHP,JSP is executed at the server and the output is sent to the webbrowser in html format or watever the HTTPResponse is set to.

XML requires a structure so, even though html contains Tags, most of the time people dont end the tags.

<book Id="Book1">

<author>Amardeep Singh</author>

</book>

XML needs to be well formed and u can use XSLT to do more stuff with it. Also u can use XPath to query XML document , but i only do xml in ASP.net so i dont know wat api functionality jsp provides.

Neways, like Khalsa said, If you are trying to create an XML document by running the jsp page then thats simple enough.

If you are trying to send an XML document to a jsp page for processing then thats probably doable.

Can you be more clearer please?

Link to comment
Share on other sites

Thats pretty easy, your output will be an xml file.

you can store the string in the xml format like this

String xml_file = "<person_info>" +

"<name>" +

"<first_name>" + request.getParameter("first_name") +"</first_name>" +

"<second_name>" + request.getParameter("second_name") +"</second_name>" +

"</name>" +

....

.....

......

.......

......

"</person_info>";

and then just output the string like

<%= xml_file %>

Link to comment
Share on other sites

Khalsa's reply is good, by string concatination u can build up a XML document.

Also if u set the resonsetype of the Response to "text/xml" then i think u can send the string to the browser and it will be displayed as an xml document, providing the xml document is valid.

i would suggest an alternative solution to this though.if you build a template xml file and then load that at runtime. then u can assign a value to each node>

this way you dont get that messy string handling that you end up doing in the above solution wont be needed.

So all u need is to build up an external xml file with the required structure.

Load it into memory using one of the api functions.

Assign values to the each node using the values captured from the form post.

And then do wat u want with the output, maybe save it to an external xml file.

Link to comment
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...