Running the XMLNSC Validation sample

You must have deployed the sample message flow and message set before you can run the sample.

If you encounter any problems when you run the sample, see Resolving problems when running samples in the WebSphere Message Broker documentation.

Running the sample with a message that passes validation

To run the XMLNSC Validation sample with a message that passes validation:

  1. In the Broker Development view, expand the XMLNSCVALIDATIONMF message flow project, then double-click XMLNSCVALIDATIONMF1.mbtest to open it in the Test Client.
  2. Right-click Invoke Message Flow in the Message Flow Test Events pane and click Invoke.
  3. In the Body field, select Import from external file, click Workspace and navigate to file ValidMessage.xml from the XMLNSCVALIDATIONMF directory in your workspace.
  4. Click OK.
  5. Click Send Message.

    The input message passes all validation checks. In the Test Client a message is retrieved from the XMLNSCVALIDATIONMF1.OUT queue, and a copy of the input message is displayed under Message in the Test Client.

Running the sample with a message that is missing data

To run the XMLNSC Validation sample, where the input message fails validation because of missing data:

  1. Right-click Invoke Message Flow in the Message Flow Test Events pane and click Invoke.
  2. In the Body field, select Import from external file, click Workspace and navigate to file MissingElement.xml from the XMLNSCVALIDATIONMF directory in your workspace. This message contains the following part:
    <Header Title="MissingElement"></Header>
    
  3. Click OK.
  4. Click Send Message.

    The input message fails validation. In the Test Client a message is retrieved from the XMLNSCVALIDATIONMF1.FAIL queue, and part of the Exception List is displayed as an XML message. This ExceptionList message contains the following part:

    <Text>Unexpected end element event.
    The content of element 'Header' is not complete.</Text>
    

    The reason for the validation failure is because the input message must have an element called SaleListCount as a child of Header. The following section of the XML schema SampleMessageValidation.xsd is where this requirement is defined:

    <xsd:complexType name="Header">
    <xsd:sequence>
    <xsd:element name="SaleListCount" type="xsd:int"></xsd:element>
    </xsd:sequence>
    <xsd:attribute name="Title" type="xsd:string" use="optional"></xsd:attribute>
    </xsd:complexType>
    

Running the sample with a message with a numeric field that is out of range:

To run the XMLNSC Validation sample, where the input message fails validation because of a numeric field that is out of range:

  1. Right-click Invoke Message Flow in the Message Flow Test Events pane and click Invoke.
  2. In the Body field, select Import from external file, click Workspace and navigate to file NumericOutOfRange.xml from the XMLNSCVALIDATIONMF directory in your workspace. The message contains the following part:
    <Quantity>1010</Quantity;>
    
  3. Click OK.
  4. Click Send Message.

    The input message fails validation. In the Test Client a message is retrieved from the XMLNSCVALIDATIONMF1.FAIL queue, and part of the Exception List is displayed as an XML message. This ExceptionList message contains the following part:

    <Text>cvc-maxInclusive-valid: The value "1010" is not valid with 
    respect to the maxInclusive facet with value "100" for type "#Anonymous".</Text>
    

    The reason for the validation failure is because the value of Quantity in the input message must be an integer in the range 1 through 100 inclusive. The following section of the XML schema SampleMessageValidation.xsd is where this requirement is defined:

    <xsd:element name="Quantity">
    	<xsd:simpleType>
    		<xsd:restriction base="xsd:int">
       			<xsd:minInclusive value="1"/>
      			<xsd:maxInclusive value="100"/>
      		</xsd:restriction>
    	</xsd:simpleType>
    </xsd:element>
    

Running the sample with an element that does not conform to the required pattern:

To run the XMLNSC Validation sample, where the input message fails validation because the value of an element does not conform to the required pattern:

  1. Right-click Invoke Message Flow in the Message Flow Test Events pane and click Invoke.
  2. In the Body field, select Import from external file, click Workspace and navigate to file PatternMismatch.xml from the XMLNSCVALIDATIONMF directory in your workspace. The message contains the following part:
    <Code>0#</Code>
    
  3. Click OK.
  4. Click Send Message.

    The input message fails validation. In the Test Client a message is retrieved from the XMLNSCVALIDATIONMF1.FAIL queue, and part of the Exception List is displayed as an XML message. This ExceptionList message contains the following part:

    <Text>cvc-pattern-valid: The value "0#" is not valid with respect to 
    the pattern facet for type "#Anonymous".</Text>
    

    The reason for the validation failure is because the value of Code in the input message must be alphanumeric. The following section of the XML schema SampleMessageValidation.xsd is where this requirement is defined:

    <xsd:element maxOccurs="3" minOccurs="3" name="Code">
    	<xsd:simpleType>
    		<xsd:restriction base="xsd:string">
    			<xsd:pattern value="[0-9a-zA-Z]{2}"/>
    		</xsd:restriction>
    	</xsd:simpleType>
    

Running the sample with a numeric field that contains non-numeric data:

To run the XMLNSC Validation sample, where the input message fails validation because a numeric field contains non-numeric data:

  1. Right-click Invoke Message Flow in the Message Flow Test Events pane and click Invoke.
  2. In the Body field, select Import from external file, click Workspace and navigate to file StringInNumeric.xml from the XMLNSCVALIDATIONMF directoryin your workspace. The message contains the following part:
    <Balance>$00.50</Balance>
    
  3. Click OK.
  4. Click Send Message.

    The input message fails validation. In the Test Client a message is retrieved from the XMLNSCVALIDATIONMF1.FAIL queue, and part of the Exception List is displayed as an XML message. This ExceptionList message contains the following part:

    <Text>cvc-datatype-valid.1.2: The value "$00.50" is not a valid value 
    for the "float" datatype.</Text>
    The reason for the validation failure is because the value of Balance must be a float, and the dollar symbol is not a valid character for a float datatype. The following section of the XML schema SampleMessageValidation.xsd is where this requirement is defined:
    <xsd:element name="Balance" type="xsd:float"></xsd:element>
    

Run the sample with a field that is too long:

To run the XMLNSC Validation sample, where the input message fails validation because a field is too long:

  1. Right-click Invoke Message Flow in the Message Flow Test Events pane and click Invoke.
  2. In the Body field, select Import from external file, click Workspace and navigate to file StringTooLong.xml from the XMLNSCVALIDATIONMF directoryin your workspace. The message contains the following part:
    <Surname>Braithwaaaaaaaaaaaite</Surname>
    
  3. Click OK.
  4. Click Send Message.

    The input message fails validation. In the Test Client a message is retrieved from the XMLNSCVALIDATIONMF1.FAIL queue, and part of the Exception List is displayed as an XML message. This ExceptionList message contains the following part:

    <Text>cvc-maxLength-valid: The length of value "Braithwaaaaaaaaaaaite" 
    is "21" which is not valid with respect to maxLength facet with value "20" 
    for type "#Anonymous".</Text>
    

    The reason for the validation failure is because the maximum length of Surname must be 20, whereas the length in the message is 21. The following section of the XML schema SampleMessageValidation.xsd is where this requirement is defined:

    <xsd:element name="Surname">
    	<xsd:simpleType>
    		<xsd:restriction base="xsd:string">
    			<xsd:maxLength value="20"/>
    		</xsd:restriction>
    	</xsd:simpleType>
    </xsd:element>
    

Run the sample with the value of an element that is not in the list of permitted values:

To run the XMLNSC Validation sample, where the input message fails validation because the value of an element is not in the list of permitted values:

  1. Right-click Invoke Message Flow in the Message Flow Test Events pane and click Invoke.
  2. In the Body field, select Import from external file, click Workspace and navigate to file ValueNotInList.xml from the XMLNSCVALIDATIONMF directory in your workspace. The message contains the following part:
    <Currency>FRF</Currency>
    
  3. Click OK.
  4. Click Send Message.

    The input message fails validation. In the Test Client a message is retrieved from the XMLNSCVALIDATIONMF1.FAIL queue, and part of the Exception List is displayed as an XML message. This ExceptionList message contains the following part:

    <Text>cvc-enumeration-valid: The value "FRF" is not valid with respect 
    to the enumeration facet for type "#Anonymous". It must be a value from the 
    enumeration.</Text>
    

    The reason for the validation failure is because the Currency element must contain one of the permissable values defined in the schema. The value in the input message does not match any of the values in the list. The following section of the XML schema SampleMessageValidation.xsd is where this requirement is defined:

    <xsd:element name="Currency">
    	<xsd:simpleType>
    		<xsd:restriction base="xsd:string">
    			<xsd:enumeration value="USD"/>
    			<xsd:enumeration value="GBP"/>
    			<xsd:enumeration value="Sterling"/>
    			<xsd:enumeration value="EUR"/>
    			<xsd:enumeration value="Euros"/>
    			<xsd:enumeration value="JPY"/>
    		</xsd:restriction>
    	</xsd:simpleType>
    </xsd:element>
    

Run the sample with an input message with the wrong namespace:

To run the XMLNSC Validation sample, where the input message fails validation because it has the wrong namespace:

  1. Right-click Invoke Message Flow in the Message Flow Test Events pane and click Invoke.
  2. In the Body field, select Import from external file, click Workspace and navigate to file NamespacedMessage.xml from the XMLNSCVALIDATIONMF directory in your workspace. The message contains the following part:
    <samp:SaleListMessage xmlns:samp="http://www.samplemessage.broker.hursley.ibm.com" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.samplemessage.broker.hursley.ibm.com/SampleMessageNamespace1.xsd">
    
  3. Click OK.
  4. Click Send Message.

    The input message fails validation. In the Test Client a message is retrieved from the XMLNSCVALIDATIONMF1.FAIL queue, and part of the Exception List is displayed as an XML message. This ExceptionList message contains the following part:

    <Text>Unexpected root tag. Element "samp:SaleListMessage" is not a 
    global element.</Text>
    The reason for the validation failure is because the the global element SaleListMessage has no target namespace defined in the schema. The instance in the input message has a root tag called SaleListMessage with a namespace, making it different to what is expected from the schema definition. The following section of the XML schema SampleMessageValidation.xsd is where this requirement is defined:
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="SaleListMessage" type="RootMessage"></xsd:element>
    

When you have completed these steps, you have successfully run the XMLNSC Validation sample. For information about the structure of XMLNSC validation exceptions, see Validation Properties.

Back to sample home