Tuesday, 8 July 2008

Schema Tools

There are already lots of commercial tools out there for editing and managing XSDs but I wanted to create my own. I don't want to pay for a commercial tool, and I'll learn a lot in the process. The goals for the toolset are quite modest:

1) Given a schema and a root element, generate the element/attribute tree for that infoset.

When you are handed a new schema, it is usually helpful to be able to see what an instance document should look like. Of course, a single schema can validate potentially many different infosets, so the client must be capable of generating the infoset for any given root element.

2) Automatically generate test instance documents.

This is a natural extension of (1). In any application involving the processing of schema-constrained XML, you need to be able to test against valid and invalid instance documents, and to achieve full test coverage for any non-trivial schema you will need a lot of instance documents. This is possibly the most useful application for this project.

Schema types mostly correspond with domain types (i.e. ignoring metadata) and you ideally want to be able to use representative test-data. For instance, if the domain includes people's names, you would prefer to use a pool of semi-realistic family-name/given-name lists, instead of random sequences of characters. So the tool will also allow you to create lists of values and associate them with schema components, using data from the appropriate list when generating test instances.

3) Schema-driven UI generation and XForms

It follows from the previous two items that you will want to look at the XML instance data, not just when testing but also in the application. It's possible to look at the XML text, but it's much nicer to be able to create some sort of form or dialog which presents the data in a more natural way, e.g. as a set of label/text pairs. This part of the tool is intended to help with that; guided by the XSD and some input from the user, the tool will generate a UI for the instance document. I haven't decided which UI to target yet, but it's likely to be Swing/rich-client to start with. Eventually, I will want to generate web forms and XForms.

I've managed to implement (1) already. I'm not sure it covers every case yet, but it does work. The code is messy and the presentation is currently a tiny Swing application. My goal for the UI is to create a Netbeans module, and integrate it into the Netbeans IDE alongside the existing (excellent) schema support. If I can integrate my commands into the NB context menu, the ideal is to trigger my functionality from inside the standard NB schema views.

I have a few more ideas for exploiting this code, but those listed above are a good start I think. Once I have working code I'm prepared to release, I will post something online for people to play with (and/or tear apart).

No comments:

Post a Comment