Show TOC

Procedure documentationRules on XML Locate this document in the navigation structure

 

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:

    Syntax Syntax

    1. <xs:element name="purchaseorder" type="PurchaseOrderType"/>
    2. <xs:element name="comment" type="xs:string"/>
    3. <xs:complexType name="PurchaseOrderType"/>
    4. <xs:sequence>
    5. <xs:element name="customerCode" type="xs:string"/>
    6. <xs:element ref="comment" minoccurs="0"/>
    7. </xs:sequence>
    8. <xs:attribute name="orderDate" type="xs:date"/>
    9. <xs:complexType>
    End of the code.
  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 Example

    If

    purchaseOrder/@orderDate Less Than 12/25/2008

    Then

    purchaseOrder/comment = {“Happy Christmas”}

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

    Input

    Syntax Syntax

    1. <purchaseOrder orderDate="12/20/2008">
    2. <p:comment></p:comment>
    3. </purchaseOrder>
    End of the code.

    Output

    Syntax Syntax

    1. <purchaseOrder orderDate="12/20/2008">
    2. <p:comment>Happy Christmas</p:comment>
    3. </purchaseOrder>
    End of the code.

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 Example

Consider the following XSD for mixed type:

End of the example.

Syntax Syntax

  1. <xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" targetNamespace = "http://tempuri.org/sizes.xsd" xmlns = "http://tempuri.org/sizes.xsd" elementFormDefault ="qualified">
    
  2. <xs:element name="letter">
  3. <xs:complexType mixed="true">
  4. <xs:sequence>
  5. <xs:element name="name" type="xs:string"></xs:element>
  6. <xs:element name="orderid" type="xs:integer"></xs:element>
  7. <xs:element name="shipdate" type="xs:date"></xs:element>
  8. </xs:sequence>
  9. </xs:complexType>
  10. </xs:element>
  11. </xs:schema>
End of the code.

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

Following is an XMl for this XSD

Syntax Syntax

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <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 ">
  3. Dear Mr.<p:name>p:name</p:name>,
  4. Your Order<p:orderid>1032</p:orderid>has arrived.
  5. And it will be shipped on<p:shipdate>2001-01-01</p:shipdate>.
  6. </p:letter>
End of the code.
Union Types

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

Example Example

Consider the following XSD for union type:

End of the example.

Syntax Syntax

  1. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/sizes.xsd"
    xmlns="http://tempuri.org/sizes.xsd" elementFormDefault="qualified">
  2. <xs:element name="size" type="SizeType"></xs:element>
  3. <xs:simpleType name="SizeType">
  4. <xs:union memberTypes="DressSizeType xs:integer"></xs:union>
  5. </xs:simpleType>
  6. <xs:simpleType name="SizeTypes">
  7. <xs:restriction base="xs:string">
  8. <xs:enumeration value="small"></xs:enumeration>
  9. <xs:enumeration value="medium"></xs:enumeration>
  10. <xs:enumeration value="large"></xs:enumeration>
  11. </xs:restriction>
  12. </xs:simpleType>
  13. <xs:simpleType name="DressSizeType">
  14. <xs:restriction base="xs:integer">
  15. <xs:minInclusive value="2"></xs:minInclusive>
  16. <xs:maxInclusive value="18"></xs:maxInclusive>
  17. </xs:restriction>
  18. </xs:simpleType>
  19. </xs:schema>
End of the code.

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 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.

End of the example.

Syntax Syntax

  1. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/sizes.xsd"
    xmlns="http://tempuri.org/sizes.xsd" elementFormDefault="qualified">
  2. <xs:element name="classRoom" type="ClassRoomType"></xs:element>
  3. <xs:complexType name="ClassRoomType">
  4. <xs:sequence>
  5. <xs:element name="student" type="StudentType"></xs:element>
  6. </xs:sequence>
  7. </xs:complexType>
  8. <xs:complexType name="StudentType" abstract="true">
  9. <xs:sequence>
  10. <xs:element name="fname" type="xs:string"></xs:element>
  11. <xs:element name="lname" type="xs:string"></xs:element>
  12. <xs:element name="stdid" type="xs:string"></xs:element>
  13. </xs:sequence>
  14. </xs:complexType>
  15. <xs:complexType name="GradStudentType">
  16. <xs:complexContent>
  17. <xs:extension base="StudentType">
  18. <xs:sequence>
  19. <xs:element name="gradyear" type="xs:string"></xs:element>
  20. <xs:element name="gradcourse" type="xs:string"></xs:element>
  21. <xs:element name="gradpercentage" type="xs:string"></xs:element>
  22. </xs:sequence>
  23. </xs:extension>
  24. </xs:complexContent>
  25. </xs:complexType>
  26. </xs:schema>
End of the code.

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 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.

End of the note.