简体   繁体   中英

Matching elements in an xml file with their declarations in a schema

I want to write an application that takes an XML-schema as input and has the following use cases:

  1. Instantiate the schema. (ie create random XML instances that conform to the schema.)
  2. 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 sequence s, replacing elements by other choice s, adding/removing optional attribute s, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM