I want to write an application that takes an XML-schema as input and has the following use cases:
- Instantiate the schema. (i.e. create random XML instances that conform to the schema.)
- Traverse such an XML instance and change values of the elements and their attributes without violating the schema. (This includes adding/removing elements to/from sequences, replacing elements by other choices, adding/removing optional attributes, etc.)
Basically I need a way of representing both the schema and the XML instance in memory, that would allow me to match elements in the instance with elements in the schema.
Preferably it should be general enough to handle DTD, XSD, and RELAX NG; however, handling XSD will also suffice.
So my question is: Is there a library that allows me to do just that?
Dom4J is a very good java xml library. I don’t think any library will do your first use-case out of the box, but it should be relatively easy to implement yourself.
For schema validation they use Xerces, which might be enough to do what you want. Never used it directly, though.