Last week I was working on a web interface, Where I wanted to get/post some data from/to the server in XML Format without posting back the page.
Well, XMLHTTP was the best method around with POST method.
Basically, The method can be implemented in the following manner:
- Add the given HTML Button on the page.
- Create an ASPX Page.
- Remove the HTML, Head and Body Sections, so that it contains only the Code Behind linking information.
- In The Page Load Event of this page, Create a StreamReader Object.
- Read The Input Stream In The Reader, Load it in XML Document Object.
- Process The XML as required.
- Send back the XML to the client calling.
Some important points are:
- Before sending the XML as String to the ASPX Page, replace the < with < and > with > to avoid a Potentially Dangerous Request Error. (The given function is already doing that)
So The basic flow is like:
- Do the required actions to get the XML Data.
- Post the XML Data as string to the aspx page.
- Read the Posted XML Data in the ASPX Page through Input Stream.
- Do the modifications required in the XML Data after loading it in a XML Document object.
- Write the XML Data as String back in the Response.