# Simantics XML-Schema Conversion version 0.1 The bundles that implement this functionality are: * org.simantics.xml.sax.base * org.simantics.xml.sax * org.simantics.xml.sax.feature * org.simantics.xml.sax.ontology * org.simantics.xml.sax.ui They are located in the [simantics/interop](https://gitlab.simantics.org/simantics/interop) project. ## Summary Simantics XML-Schema conversion creates: * Simantics ontology as .pgraph file * Java classes for SAX based parser Schema conversion does not support: * XML file export * Many of the XML schema definitions * Group definitions * Attribute constraining facets ## Notes This work was done in PDS Integration project in co-operation with VTT and Fortum. Schema conversion was used for converting Proteus 3.6.0 XML Schema to Simantics ontology. Due to limited scope of the schema, the converter supports only limited part of the XML Schema definitions. # Ontology definitions based on XML schema concepts XML Schema conversion creates types and relations based on XML schema concepts that are used in the conversion | Hard-coded ontology definition | Notes | |----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | hasAttribute These are from … ``` ``` PRO.hasLengthUnitsType L0.String PRO.hasUnitsOfMeasure ``` ``` PRO.ComplexTypes.hasKnots.Knot … ``` ``` PRO.ComplexTypes.PlantItem PRO.ComplexTypes.PlantItem PRO.ComplexTypes.PlantItem.hasPresentation PRO.Presentation PRO.ComplexTypes.PlantItem.hasExtent PRO.Extent … PRO.ComplexTypes.PlantItem.hasID L0.String … PRO.ComplexTypes.PlantItem.hasComponentType L0.String ``` ## Element Element definitions are processed similarly to ComplexTypes, but the converted types are put directly into the ontology without any library. Hence, Element “PlantModel” is converted to “PlantModel” entity. ```xml ``` ``` PRO.hasPlantModel PRO.PlantInformation PRO.PlantModel.hasExtent PRO.Extent ``` When Element definition is defined with ComplexContent, ComplexContent’s extension’s base is converted to L0.Inheritance relation between the types. For example “Equpiment” Element has “PlantItem” as a base extension, so “Equipment” entity is inherited from “PlantItem” entity. ```xml ``` ``` PRO.hasEquipment L0.String PRO.Equipment.hasPurpose L0.String PRO.Equipment.hasDiscipline PRO.Discipline PRO.Equipment.hasMinimumDesignPressure PRO.MinimumDesignPressure … PRO.Equipment.hasEquipment PRO.Equipment … ``` ## Indicators (choice, sequence, all) When Indicators have maxOccurs larger than 1, relations generated according to particles have no multiplicity restrictions (ass all previous examples are defined). When indicator is choice with maxOccurs=1 (default value for maxOccurs), the particle relations is expected to refer to only one object that conforms to one of the specified types. For example, Element “TrimmedCurve” has choice indicator with 4 elements (“Circle”, “PCircle”, “Ellipse”, “PEllipse), and that choice is converted to “TrimmedCurve.hasCircleOrPCircleOrEllipseOrPEllipse” relation. ```xml ``` ``` PRO.hasTrimmedCurve L0.Double PRO.TrimmedCurve.hasEndAngle L0.Double PRO.TrimmedCurve.hasCircleOrPCircleOrEllipseOrPEllipse PRO.Circle --> PRO.PCircle --> PRO.Ellipse --> PRO.PEllipse PRO.TrimmedCurve.hasGenericAttributes PRO.GenericAttributes ``` Note that Model Group definitions are not currently supported! # Customization via configuration ## Attribute composition Attribute composition rule allows converting separate attributes into one array. For example, following rule: ```xml causes “X”, “Y” and “Z” double attributes in “Coordinate” Element definition ``` to be converted to “XYZ” double array: ``` PRO.Coordinate L0.DoubleArray ``` ## ID references Referencing other XML elements is usually done using element IDs. Using ID Provider and ID Reference rules allows converting these references to statements in Simantics DB. ID Provider rule is used for retrieving the ID from referred objects. The rule does not affect the generated ontology. ```xml ``` ID Reference rule is used for objects that use ID references. ID Source tells which attribute is used to refer another Element, and Reference defines the name of the relation. With the following rule: ```xml ``` “Connection” element definition’s “ToID” reference is converted to ToIDRef relation. ```xml ``` The original attribute is kept, so that if ID reference cannot be located, the information about the reference still exists. ``` PRO.Connection L0.String PRO.Connection.ToIDRef ``` ## Unrecognized child elements Unrecognized child element rule allows processing XML files that do not conform to given schema, and use different element names. In practice, the rule allows injecting Java code to generated parser classes. The code is put into method, which signature is: ```java public void configureChild(WriteGraph graph, Deque parents, Element element, Element child) throws DatabaseException ``` The method is called with ”element” as the element, which conforms to given type in the rule’s configuration, and ”child” is the child element, that could not be recognized. The following example is used for handling incorrect files, which have replaced element name with the contents of attribute “name”. ```xml // Some commercial software do not handle GenericAttribute elements properly: // they use "Name" attribute's value as element's name. GenericAttribute ga = new GenericAttribute(); java.util.List<Attribute> attributes = new java.util.ArrayList<Attribute>(); attributes.addAll(child.getAttributes()); attributes.add(new Attribute("Name", "Name", "", child.getQName())); Element newChild = new Element("", "", "GenericAttribute", attributes); newChild.setParser(ga); Resource res = ga.create(graph, newChild); if (res != null) { newChild.setData(res); parents.push(element); ga.configure(graph, parents, newChild); connectChild(graph, element, newChild); parents.pop(); } ``` An example of incorrect file: ```xml ``` When the content should be: ```xml ``` # References * W3C XML Schema definition language (XSD) 1.1 Part 1: Structures http://www.w3.org/TR/xmlschema11-1/ * W3C XML Schema definition language (XSD) 1.1 Part 2: Datatypes http://www.w3.org/TR/xmlschema11-2/ * [Layer0 specification](Layer0.pdf)