views:

69

answers:

4

I have to write a small web application in Java that displays the contents of an XML to the user as a form. The user can then modify the form entries and the changes get saved to the XML.

I want to know

  • What is the standard way to write such an application? I mean should I manually write code to parse the XML into Java object(s), display on the web page and then rewrite the changes back to the XML? Or are there any standard tools available that can automate some of these steps ?

  • How do I manage locking in case of multiple users trying to update the same XML?

By the way, I am open to use any language/framework if it offers an easy low effort solution.

The tool is meant to be used by production support engineers to modify production specific configuration XML.

A: 

Did you have a look at the XFORMS model ? Could be of interest

Pierre
+1  A: 

Never, ever write your own XML parser.

Yes, Java (i.e., JSP) has built-in libraries for loading and saving XML files.

Writing the code to make the HTML form, populate it with the XML element information, take the form POST back from the client, and write it back into an updated XML file is all pretty straightforward, but it'll be a lot of work, particularly if the form is complicated.

Locking is an issue: web connections are stateless. Poor-man's solution: rename the XML file (say, 1.xml to 1.xml.checkedout) while it is being edited. Rename it back after saving it. Pass the filename with the form back to the server so your server-side code knows which file to write to and rename back. Down side is that users who abandon the web page will leave renamed carnage behind.

On the server side, PHP, JSP, ASP.NET, Perl, and Python would all be just fine for this application. It's all about what you feel most comfortable working in.

Remember, since you aren't storing the XML in a database, the web server will need write access to the literal XML files.

richardtallent
A: 

I would normally use a combination of XML Serialization and the .NET framework.

Load and save objects to XML using serialization

kevchadders
A: 

We recently worked on a similar project in c#, but the principles should be the same. We didn't really have the same issues with conflict management since we versioned the file in a table and then gave merge functionality to the user if someone else overwrote their data.

The problem became much easier when we decided we would use xslt to tranform the xml into the xhtml forms. Depending on the complexity of the xml (and the resulting form), this could probably be done relatively quickly. You can then perform the transformtation (in most languages) in a single line.

What made this work so well was that we could use the form element name attributes to pass along the xpath of every node we were trying to update (getting this in xslt is pretty easy). We would then have a direct reference to the data being updated. After validating the user input, you can then update the xml with a few lines, too.

It ended up being a beautifully elegant solution (just the sort of thing that xml, xslt, and xquery are designed for). The best part is that it translates nicely to any language that has relatively-good xml tools. This approach also makes it very easy to add functionality to the form or provide alternate views on the data.

Jason Francis