• 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

Creating xml documents dynamically based on a schema

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a java form in Swing that has fields for user input. What I need to do is to get that user input into xml format that conforms to an xml schema I created.
Is it possible to do this with DOM? I saw a createDocumentType function that seems like it might be what I need. Does that sound right? Any help would be greatly appreciated.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would just write straight-forward Java code, which takes the input and writes the corresponding XML into a PrintWriter/StringWriter.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Even I have a similar kind of doubt. I have been using classes from the com.docuverse.dom package for creating a DOM structure for a XML file. But whenever I am creating such a file I need to get the initial root element from an already existing XML file.
In other words I first parse an already existing XML template file using the DOMParser of org.apache.xercers.parsers package. From this I get the Document of the XML file and from there I get the Root Element to which I add the rest of the elements. Can I not create a Document and append elements to it from scratch and then write the whole structure to a file?
Can anyone provide me with any kind of tutorials / links / help that will help me do the same?
 
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As lasse mentioned, I tyhink the straigt forward way to do it is to write it using a fileoutputstream as follows !!!

DOM does provide an Interface called DOMImplementation that allows you to create a new Document based on a DTD. You can then add elemnts and attributes using the Document interface. I am not sure if tehre is one for schema .
The methods defined in teh interface are as follows

An example of doing ot using this would be as follows

Hope this helps
hari
 
Ketan KC Chachad
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Hari Vignesh Padmanaban for the code. But can you provide me with some links for that will help me understanding the API more? Some kind of Tutorials of any kind. It will be a big help. Thanks in advance. This request goes to everyone who can help me
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic