Projection of Literal Properties to XML Schemas
Projection of Literal Properties to XML Schemas
This section discusses how literal (non-collection) properties are projected to XML types, as well as options that affect the XML schema. It discusses the following:
Default XSD Types for InterSystems IRIS Data Type Classes
If a class or a class property is based on one of the common InterSystems IRIS data type classes, the XML type is set automatically, according to the following table. Classes in the %xsd package map directly to the XML types, as shown in the table.
For information on the XML data types, see https://www.w3.org/TR/xmlschema-2/Opens in a new tab.
For example, consider the following class:
Class Schema.DataTypesDemo Extends (%RegisteredObject, %XML.Adaptor)
{
Parameter XMLTYPENAMESPACE="mytypes";
Property binaryprop As %xsd.base64Binary;
Property booleanprop As %Boolean;
Property dateprop As %Date;
Property datetimeprop As %TimeStamp;
Property decimalprop As %Numeric;
Property integerprop As %Integer;
Property stringprop As %String;
Property timeprop As %Time;
}
The schema for this class is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:s="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="mytypes">
<complexType name="DataTypesDemo">
<sequence>
<element minOccurs="0" name="binaryprop" type="s:base64Binary"/>
<element minOccurs="0" name="booleanprop" type="s:boolean"/>
<element minOccurs="0" name="dateprop" type="s:date"/>
<element minOccurs="0" name="datetimeprop" type="s:dateTime"/>
<element minOccurs="0" name="decimalprop" type="s:decimal"/>
<element minOccurs="0" name="integerprop" type="s:long"/>
<element minOccurs="0" name="stringprop" type="s:string"/>
<element minOccurs="0" name="timeprop" type="s:time"/>
</sequence>
</complexType>
</schema>
Compiler Keywords That Affect the Schema
The Required keyword affects the XML schema, by removing the minOccurs="0" attribute. For example, consider the following class:
Class Schema.PropKeywords Extends (%RegisteredObject, %XML.Adaptor)
{
Parameter XMLTYPENAMESPACE="mytypes";
Property Property1 As %String;
Property Property2 As %String [ Required ];
}
If we generate a schema for the namespace used here, we see the following:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:s="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="test">
<complexType name="PropKeywords">
<sequence>
<element minOccurs="0" name="Property1" type="s:string"/>
<element name="Property2" type="s:string"/>
</sequence>
</complexType>
</schema>
Note that the default for minOccurs is 1; that is, Property2 is required.
For compatibility reasons, %XML.ReaderOpens in a new tab does not check for required properties by default, but you can cause it to do so; see Checking for Required Elements and Attributes. Also by default, an InterSystems IRIS web service does not check for required properties, but you can cause it to do so; see Checking for Required Elements and Attributes.
No other property keywords affect the schema for data type classes.
Parameters That Affect XML Schemas
The InterSystems IRIS data type classes use many parameters. (For a table that lists the parameters supported in each data type class, see Data Types.) In most cases, you can also specify these as property parameters.
The parameters that affect XML schemas are as follows:
Influences how the property values are escaped; see Handling Special XML Characters.
The "MIXED" value causes a change in the schema, as compared to the other possible values. Consider the following class:
Class Schema.CONTENT Extends (%RegisteredObject, %XML.Adaptor)
{
Parameter XMLTYPENAMESPACE = "mytypes";
Property Property1 As %String;
Property Property2 As %String(CONTENT = "STRING");
Property Property3 As %String(CONTENT = "ESCAPE");
Property Property4 As %String(CONTENT = "MIXED");
}
If we generate a schema for the namespace used here, we see the following:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:s="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="mytypes">
<complexType name="CONTENT">
<sequence>
<element minOccurs="0" name="Property1" type="s:string"/>
<element minOccurs="0" name="Property2" type="s:string"/>
<element minOccurs="0" name="Property3" type="s:string"/>
<element name="Property4">
<complexType mixed="true">
<choice maxOccurs="unbounded" minOccurs="0">
<any processContents="lax"/>
</choice>
</complexType>
</element>
</sequence>
</complexType>
</schema>
Notice that the three of these properties have the same type information, because XML treats them in the same way. InterSystems IRIS, however, treats the properties differently as described in Handling Special XML Characters.
If you use the object as input or output for a web method, and SoapBodyUse is encoded for that method, then InterSystems IRIS treats mixed content like string content, the default. That is, if you specify CONTENT as "MIXED", that value is ignored.
Affects the schema if VALUELIST is also specified and if XMLLISTPARAMETER equal to "DISPLAYLIST". See the discussions for those two parameters.
Controls the maxLength attribute, which is a facet or restriction. Facets define acceptable values for XML types. The following example shows several of them. Consider the following class:
Class Schema.BasicFacets Extends (%RegisteredObject, %XML.Adaptor)
{
Parameter XMLTYPENAMESPACE = "mytypes";
Property Property1 As %Integer (MINVAL=10, MAXVAL=1000);
Property Property2 As %String (MINLEN=20, MAXLEN=100);
}
If we generate a schema for the namespace used here, we see the following:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:s="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="mytypes">
<complexType name="BasicFacets">
<sequence>
<element minOccurs="0" name="Property1">
<simpleType>
<restriction base="s:long">
<maxInclusive value="1000"/>
<minInclusive value="10"/>
</restriction>
</simpleType>
</element>
<element minOccurs="0" name="Property2">
<simpleType>
<restriction base="s:string">
<maxLength value="100"/>
<minLength value="20"/>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
</schema>
Controls the maxInclusive attribute. See the example in MAXLEN.
Controls the minLength attribute. See the example in MAXLEN.
Controls the minInclusive attribute. See the example in MAXLEN.
Adds an <enumeration> restriction to the type. Consider the following class:
Class Schema.VALUELIST Extends (%RegisteredObject, %XML.Adaptor)
{
Parameter XMLTYPENAMESPACE = "mytypes";
Property Property1 As %String;
Property Property2 As %String (VALUELIST = ",r,g,b");
}
The following shows the schema for this class:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:s="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="mytypes">
<complexType name="VALUELIST">
<sequence>
<element minOccurs="0" name="Property1" type="s:string"/>
<element minOccurs="0" name="Property2">
<simpleType>
<restriction base="s:string">
<enumeration value="r"/>
<enumeration value="g"/>
<enumeration value="b"/>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
</schema>
Applicable to a %NumericOpens in a new tab property. This parameter corresponds to the <fractionDigits> facet, as shown in the following fragment:
<element minOccurs="0" name="Property2">
<simpleType>
<restriction base="s:decimal">
<fractionDigits value="2"/>
<totalDigits value="5"/>
</restriction>
</simpleType>
</element>
Applicable to a %NumericOpens in a new tab property or an %IntegerOpens in a new tab property. This parameter corresponds to the <totalDigits> facet, as shown in the following fragment:
<element minOccurs="0" name="Property2">
<simpleType>
<restriction base="s:decimal">
<fractionDigits value="2"/>
<totalDigits value="5"/>
</restriction>
</simpleType>
</element>
Applicable to a %StringOpens in a new tab property that specifies the VALUELIST parameter. Specifies the name of the parameter that contains the list of values to project to XML, instead of the values contained in the object. In most cases, you also specify the standard DISPLAYLIST parameter, and you set XMLLISTPARAMETER equal to "DISPLAYLIST".
The XMLLISTPARAMETER parameter controls the value attribute used in the <enumeration> restriction.
You cannot specify this as a property parameter.
Controls the pattern restriction. Consider the following class:
Class Schema.Pattern Extends (%RegisteredObject, %XML.Adaptor)
{
Parameter XMLTYPENAMESPACE = "mytypes";
Property Property1 As %String;
Property Property2 As %String(XMLPATTERN = "[A-Z]");
}
The schema for this class is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:s="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="mytypes">
<complexType name="Pattern">
<sequence>
<element minOccurs="0" name="Property1" type="s:string"/>
<element minOccurs="0" name="Property2">
<simpleType>
<restriction base="s:string">
<pattern value="[A-Z]"/>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
</schema>
If multiple patterns appear in a simple type, then InterSystems IRIS combines the patterns according to https://www.w3.org/TR/xmlschema-2Opens in a new tab (see section 4.3.4.3, Constraints on XML Representation of pattern). The patterns are combined as separate branches in the same pattern (separated by a vertical bar) in the XMLPATTERN parameter.
Declares the XSD type used when projecting to XML. This parameter is set appropriately in all InterSystems IRIS data type classes. The InterSystems IRIS XML tools use this parameter when generating schemas. This parameter does not directly affect the input and output transformations, although it should be consistent with them.