edit this page - page history - about editing

Loading EMF XSD Models at Runtime

EMF XML Schema XSD

I wanted to be able to get the XSDSimpleTypeDefinition of a particular defined XSD type in my Eclipse plugin environment, i.e.

http://openiaml.org/model/datatypes#iamlInteger

Which was stored in an XSD file

org.openiaml.model/model/datatypes.xsd

The solution is to load the XSD file (through a URI) at runtime using EMF, and then iterating through this file to find the relevant data types. These can then be saved and referred to as necessary.

URI uri = URI.createURI("platform:/plugin/org.openiaml.model/model/datatypes.xsd");
EObject root = ModelLoader.load(uri);
XSDSchema schema = (XSDSchema) root;
for (XSDTypeDefinition type : schema.getTypeDefinitions()) {
  // ... checks with getURI()
}

See how I implemented this in IAML.
Categories: Java | EMF | Code Snippets
edit this page - what links to here? - page history - top
Last edited by jevon jevon 93 months ago