File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating xml documents dynamically based on a schema

 
Tony Brown
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Ketan KC Chachad
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic