Show TOC

Rules on XMLLocate this document in the navigation structure

Use

This section describes the behavior of the Engine for XML Rules.

When you import an XSD file into the rules composer DC, aliases are generated by default.

For a given XSD element, the generated aliases are:

  • Get attribute value

  • Set attribute value

  • Get simpleChildElement value

  • Set simpleChildElement value

Procedure
  1. Consider the following purchaseOrder element in an XSD:

    <xs:element name="purchaseorder" type="PurchaseOrderType"/>
    <xs:element name="comment" type="xs:string"/>
    <xs:complexType name="PurchaseOrderType"/>
    <xs:sequence>
    <xs:element name="customerCode" type="xs:string"/>
    <xs:element ref="comment" minoccurs="0"/>
    </xs:sequence>
    <xs:attribute name="orderDate" type="xs:date"/>
    <xs:complexType>
                   
  2. Generated aliases for the PurchaseOrder element are:

    purchaseOrder/@orderDate

    purchaseOrder/@orderDate = {Date}

    purchaseOrder/comment

    purchaseOrder/comment = {String}

  3. Using these aliases, you can create rules with 'get methods as conditions' and 'set and get methods as actions'

    Example

    If

     

    purchaseOrder/@orderDate Less Than 12/25/2008

    Then

     
     

    purchaseOrder/comment = {"Happy Christmas"}

  4. While executing if an XML with purchaseOrder element is evaluated, then the result is as follows:

    Input

    <purchaseOrder orderDate="12/20/2008">
    <p:comment></p:comment>
    </purchaseOrder>
                   

    Output

    <purchaseOrder orderDate="12/20/2008">
    <p:comment>Happy Christmas</p:comment>
    </purchaseOrder>
                   

For a given XSD, the following XSD types are not allowed due to limitations on alias generation.

  • Complex Types with Mixed Content

  • Union Types

  • Polymorphism

Complex Types with Mixed Content

Aliases will not be generated for Mixed Complex Type

Example

Consider the following XSD for mixed type:

<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" targetNamespace = "http://tempuri.org/sizes.xsd" xmlns = "http://tempuri.org/sizes.xsd" elementFormDefault ="qualified">

<xs:element name="letter">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="orderid" type="xs:integer"></xs:element>
<xs:element name="shipdate" type="xs:date"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
            

From the above example, 'letter' is a Mixed Complex Type.

Following is an XMl for this XSD

<?xml version="1.0" encoding="UTF-8"?>
<p:letter xmlns:p="http://tempuri.org/sizes.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tempuri.org/sizes.xsd Complex.xsd ">
Dear Mr.<p:name>p:name</p:name>,
Your Order<p:orderid>1032</p:orderid>has arrived.
And it will be shipped on<p:shipdate>2001-01-01</p:shipdate>.
</p:letter>
            

Union Types

By default, we map union of all the primitive types to "java.lang.String".

Example

Consider the following XSD for union type:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/sizes.xsd" 
xmlns="http://tempuri.org/sizes.xsd" elementFormDefault="qualified">
<xs:element name="size" type="SizeType"></xs:element>
<xs:simpleType name="SizeType">
<xs:union memberTypes="DressSizeType xs:integer"></xs:union>
</xs:simpleType>
<xs:simpleType name="SizeTypes">
<xs:restriction base="xs:string">
<xs:enumeration value="small"></xs:enumeration>
<xs:enumeration value="medium"></xs:enumeration>
<xs:enumeration value="large"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="DressSizeType">
<xs:restriction base="xs:integer">
<xs:minInclusive value="2"></xs:minInclusive>
<xs:maxInclusive value="18"></xs:maxInclusive>
</xs:restriction>
</xs:simpleType>
</xs:schema>
            

From the above example 'Size' can be a Restricted String Type ('small', 'medium', 'large') or an Integer Type (2 to 18). XML that contains these values will be a valid XML.

Polymorphism

Aliases are not generated for the valid xpaths.

Example

If GradStudent extends Student, it is valid to use GradStudent instance for Student at runtime, but you cannot get the elements of GradStudent through Student as aliases of the GradStudent elements are not generated for Student.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/sizes.xsd" 
xmlns="http://tempuri.org/sizes.xsd" elementFormDefault="qualified">
<xs:element name="classRoom" type="ClassRoomType"></xs:element>
<xs:complexType name="ClassRoomType">
<xs:sequence>
<xs:element name="student" type="StudentType"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="StudentType" abstract="true">
<xs:sequence>
<xs:element name="fname" type="xs:string"></xs:element>
<xs:element name="lname" type="xs:string"></xs:element>
<xs:element name="stdid" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="GradStudentType">
<xs:complexContent>
<xs:extension base="StudentType">
<xs:sequence>
<xs:element name="gradyear" type="xs:string"></xs:element>
<xs:element name="gradcourse" type="xs:string"></xs:element>
<xs:element name="gradpercentage" type="xs:string"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
            

From the above example, Student Type is a Abstract Type i.e there cannot be an element of type student instead the element should be graduate student and GradStudentType is extending StudentType. Hence you can use GradStudentType element wherever StudentType Element is expected.

Note

When you use this type of XSD for creating aliases, aliases will not be generated for GradStudentType and as a result you cannot write rules on these aliases.