开发者

Create XML dynamically talking the data from UI

开发者 https://www.devze.com 2023-04-06 05:31 出处:网络
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 requir

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.


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!

http://jaxb.java.net/


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消