• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 25
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 112
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using DOM Parsers. Share your code, to improve on it.
 
satnam singh negi
Greenhorn
Posts: 25
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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
Posts: 25
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sorry posted so many time

 
satnam singh negi
Greenhorn
Posts: 25
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic