File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes how to generate a xml file on submit action with all the form data 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 "how to generate a xml file on submit action with all the form data" Watch "how to generate a xml file on submit action with all the form data" New topic
Author

how to generate a xml file on submit action with all the form data

satnam singh negi
Greenhorn

Joined: Aug 13, 2011
Posts: 25

Hi All, Greetings!!

i have a html or jsp file with the input values ,when i click the submit button it calls a servlet's do post method,so there i need to generate a xml file using some java code, and in that xml file i want to show all the data recieved in request.

generated xml file should look like this.


Please Help.

Thanks in advance.
Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
Can you share what have you tried and what is not working

The general steps for achieving this would be
1. Read the request
2. Create a file and populate the file based on the request parameters and your business logic
3. Write the file to the response's outputstream

Note: remember to set the content type appropriately
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

Try using DOM Parsers. Share your code, to improve on it.


Ashwin Sridhar
SCJP | SCWCD | OCA
satnam singh negi
Greenhorn

Joined: Aug 13, 2011
Posts: 25




This all work perfect for me . so the actual problem has been resolved, but now when i read the same generated file then there is always fetal error,

The element type "input" must be terminated by the matching end-tag

also when the xml file got generated it doesnt show on the top of document

how to achieve this,please share your comments !!

Thanks
satnam singh negi
Greenhorn

Joined: Aug 13, 2011
Posts: 25

sorry posted so many time
satnam singh negi
Greenhorn

Joined: Aug 13, 2011
Posts: 25

Ashwin Sridhar wrote:Try using DOM Parsers. Share your code, to improve on it.





This all work perfect for me . so the actual problem has been resolved, but now when i read the same generated file then there is always fetal error,

The element type "input" must be terminated by the matching end-tag

also when the xml file got generated it doesnt show on the top of document

how to achieve this,please share your comments !!

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

You're producing a string containing some XML, but then you say something about a "generated file". I don't see any code which generates a file there.
satnam singh negi
Greenhorn

Joined: Aug 13, 2011
Posts: 25

Paul Clapham wrote:You're producing a string containing some XML, but then you say something about a "generated file". I don't see any code which generates a file there.


the file got generated in my local machine and it looks like this



i am reading this file with this code


but it does'nt parse the file, as it through an exception like "input" element must have end tag "input"

Please suggest !!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

The error message is exactly correct. You don't have well-formed XML there.

However the code you posted does produce well-formed XML. So the data you posted wasn't produced by the code you posted.
satnam singh negi
Greenhorn

Joined: Aug 13, 2011
Posts: 25

Paul Clapham wrote:The error message is exactly correct. You don't have well-formed XML there.

However the code you posted does produce well-formed XML. So the data you posted wasn't produced by the code you posted.



right paul ,i am able to create a xml but with some restrictions. like if use an Element object and then i set the attributes of it, it does produce the well formed tag with xml but without a end tag.

still looking that how can i achieve this. another approach is like i shall read the file as string and then i have to manipulate it by inserting the end tag and then parse.

will it be a good idea ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

Nope. If you use those DOM methods to create a representation of your XML in memory, and then use an identity transformation to serialize it to disk, you will get well-formed XML. What you showed was HTML, not well-formed XML. Therefore it was not produced in that way. You should review your code and configuration to find out what is really happening.
 
Don't get me started about those stupid light bulbs.
 
subject: how to generate a xml file on submit action with all the form data