i have a requirement in which i need to create an XML from the data entered by the user. i need to perform this task in Java. the number of data fields can vary depending on user requirement. I have designed the dynamic UI using JSPs and Javascript but i m not getting how to save the data into XML and then pass on to the server.
3 Answers
depends on where do you want the form data to be converted into XML. As you say, it has to happen in Java, I think you pretty much mean the conversion has to happen on server side.
i m not getting how to save the data into XML and then pass on to the server.
why do you need to convert it to xml on client side then?
Anyways, you can easily get the Form data at server side and convert it to xml using XStream , JAXB or using simple
You can look at this SO QA for further details: XML serialization in Java?
You might want to look into JAXB. If you have a defined XML schema it will automatically create java classes that will easily allow you to 'marshal' (move data from java -> XML) and much much more. It's incredibly useful!

- 792
- 6
- 11
- 23
You can use a function that creates the xml before sending.
each time the user completes a field, the function is called and adds an entry into the xml string.
At the end, when the user clicks submit, it wraps the xml entries into start/end tags and send the created xml text to the server.
OPTION2. You can transform the form elements into JSON and convert json object into xml. I guess there should be some functions that do that.
OPTION3. Send the user raw data to the server, and let the server create the xml based on what was received.

- 1,292
- 8
- 15
-
can u please tell me how i can create xml before sending. this will best suit my requirement – simi Sep 21 '11 at 14:09
-
well, because you send it to the network, than it's just plain text with xml structure. You can do this manualy for example xmlVar += '
' + yourvalue + ' '; and so on. You should make sure at the end you will construct a string that will have a valid xml representation. – Dan Bizdadea Sep 21 '11 at 14:11 -
at the server side, you can feed this parameter to an XML parser and use it – Dan Bizdadea Sep 21 '11 at 14:12