Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What tools should I start looking at?

 
Tony Brown
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm starting a project where I have to create a Java application that outputs XML data. I want to have a check button where the user can check the validity of their input against an existing XML Schema. So if they forget to put a value into a mandatory field, the application will tell them what's missing and won't let them output the data into XML until it is valid.
Also, I want them to be able to load an XML file into the application so that the fields are filled automatically if the file is valid.
Can someone tell me which APIs I need and where I should start looking/reading? Thanks,
Tony Brown
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should do a search on this forum for "schema validation" or something similar. You'll find that it is rather simple to validate a document against a given XML schema. However, I am unable to advice you regarding your "fill in the blanks" requirement (the only way I can think of is to write a lot of code to check for fields one at a time, manually)...
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For generating XML from databases check out the OpenSource FormattedDataSet API (http://www.fdsapi.com). It can also be used to collect Form data and put it into XML format. Sample code to do this follows:
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see the following link for a demo app of converting HTML form request parameters to XML.
http://ssouza.kgbinternet.com/fdsapi/basicdemo.jsp
 
Tony Brown
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything I'm seeing seems to show validation by command line against an existing xml file.
I would like to validate dynamically against xml data in memory (such as in a DOM tree) before I write it out to a file.
Is this possible?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's always a couple of alternative parsing methods -- if the example uses a File or a FileInputStream to create a Source, you can most certainly construct the Source from in-memory data structures. Browse the java.io.* javadocs.
There's an example of schema validation using Xerces in our JavaRanch Wiki.
If you happen to use a recent enough version of JAXP, you can rely on its implementation-agnostic schema validation features. See here and here for details.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic