# Validating Schemas

In addition to the validation check box on the node builders, you can validate XML Schemas in the source code by using the code examples illustrated in this section.

If you check the Validate check box in the business process nodes, and at run time a validation error occurs, a SOAP fault is thrown and your request is stopped before it gets to the business process or any exception handler defined for your business process. To design the validation of schemas and handling of their related exceptions within a business process, you can use the validate() method as described in the examples in the following section.

The examples in this section describe only validation procedures to validate against XML Schemas. You can accomplish similar tasks for MFL data by using the WebLogic Integration MflObject interface (see Using the MflObject Interface to Transform Non-XML Data Programmatically).

The following validation scenarios are described:

- Validating a Typed XML Variable
- Typing and Validating an Untyped XML Type

## Validating a Typed XML Variable

In this example, we assume that the type of XML received by the business process is known at design time. That is, a document received by the business process is known to be strongly-typed XML. The following code describes how to deliver the XML to the business process and validate the XML data against the corresponding XML schema:

         public void receiveTypedXML(POORDERDocument lineItem) {
            if (lineItem.validate()) {
                //
            } else {
                // Handle error
            }
        }

In the preceding example, POORDERDocument is the name of the XML schema against which you want to validate the XML data received by your business process.

## Typing and Validating an Untyped XML Type

In this example, we take an untyped XML data received by your business process, convert it to a strongly typed XML data, and subsequently validate it against an XML schema associated with the type.

This can be accomplished by writing the following code:

       public void receiveUntypedXML(XmlObject xml) {
           if (xml instance of POSUBLINEDocument) {
               POSUBLINEDocument sublineItem = (POSUBLINEDocument) xml;
               if (sublineItem.validate()) {
                   // item is valid

               } else {
                   // item is not valid
               }
           } else {
               // Handle error - the XmlObject is not a POSUBLINEDocument
           }
       }

In the preceding example, POSUBLINEDocument is the name of the XML schema against which you want to validate the XML data.

Related Topics

Using the MflObject Interface to Transform Non-XML Data Programmatically

Working with Data Types

Class XmlUtils at http://edocs.bea.com/wli/docs81/javadoc/com/bea/xml/XmlUtils.html

Importing Schemas

Schemas Project Folder

How do I: Import Files into the Schemas Project Folder