aspose file tools*
The moose likes XML and Related Technologies and the fly likes converting HTML form to XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "converting HTML form to XML" Watch "converting HTML form to XML" New topic
Author

converting HTML form to XML

Mattew Lee
Greenhorn

Joined: Dec 22, 2010
Posts: 14
Hi everybody,
Merry Christmas,

Assume that there is a an HTML form in which end-user adds some data and submit it.
I wish to receive those data and convert them to XML so as to send them back to Server for further processing.

What solution do yo suggest? If JavaScript is suitable please tell me where can I find the code because I'm not familiar with JavaScript.

Cheers,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

JavaScript is not the most suitable technology for this. It'd be best to do this in Java code once the values get submitted to the server.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mattew Lee
Greenhorn

Joined: Dec 22, 2010
Posts: 14
Bear Bibeault wrote:JavaScript is not the most suitable technology for this. It'd be best to do this in Java code once the values get submitted to the server.


Thanks for your answer, if I knew how to do it definitely I wouldn't ask this question, so would you please tell me how can I do this via Java code? please note that I want to
have the form's data in XML.

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31062
    
232

XML doesn't make much sense without knowing what the schema should be. For example, these are all logical ways of representing a name:



Once you know what the data should look like, you can choose an XML parser such as DOM to build the XML. Or use String concatenation.

I'm going to move this to our XML forum for followups.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Something is not clear to me - are you able to control the code on the server side or are you forced to deal with an existing server side application?


IF you control server side code, are you able to read form parameter values?


In any case, do you have an example XML document of what your output XML should look like?

Bill
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

I wish to receive those data and convert them to XML so as to send them back to Server for further processing.


I would suggest you to use XStream Api for easily converting Java Objects to XML and Vice versa , because its easier and avoids extra processing which in case if you go for DOM or SAX .

Thanks .


Save India From Corruption - Anna Hazare.
Mattew Lee
Greenhorn

Joined: Dec 22, 2010
Posts: 14
William Brogden wrote:Something is not clear to me - are you able to control the code on the server side or are you forced to deal with an existing server side application?


IF you control server side code, are you able to read form parameter values?


In any case, do you have an example XML document of what your output XML should look like?

Bill


Example: Node names are similar to form tags. I control the server-side code.

<firstName>Data from form</firstname>
<lastName>Data from form</lastName>

Hope this helps
Mattew Lee
Greenhorn

Joined: Dec 22, 2010
Posts: 14
Ravi Kiran Va wrote:
I wish to receive those data and convert them to XML so as to send them back to Server for further processing.


I would suggest you to use XStream Api for easily converting Java Objects to XML and Vice versa , because its easier and avoids extra processing which in case if you go for DOM or SAX .
Thanks .


Thanks, I will give it a try although if you had give me a complete example that would be great since I'm not a javaScript pro.

Regards,
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5

There is nothing magic about XML, just a syntax requirement, so it doesn't matter how the elements get written.

Since you say you control the server side code, there appears to be no reason to do any creation of XML on the client side at all. Is there some reason you are not treating this as a normal form parameter processing problem?

If you absolutely have to send XML from the client, for some reason you have not explained, why not build the XML formatted request to send to the server by ordinary String writing?

Bill
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31062
    
232

I'm not sure why we are still talking about JavaScript. I think everyone in this thread agreed that Java/server side is the best place to start.

Now your decision is whether to just use String concatenation or a XML library.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: converting HTML form to XML