Salesforce

How Do I Validate an XML Document? (Magic xpa 4.x)

« Go Back

Information

 
Created BySalesforce Service User
Approval Process StatusPublished
Objective
Description

How Do I Validate an XML Document? (Magic xpa 4.x)

It is recommended that you validate an XML document before using it. If the XML is not properly formatted, or does not match the schema definitions, you may get erratic results.

Magic xpa has a built-in function to validate the XML document, XMLValidate(). This function will compare the XML document with its schema, and prepare a list of errors.

Using XMLValidate()

The basic steps to using XMLValidate are:

  1. Call XMLValidate(), storing the result in a logical. This logical will be FALSE if there are errors; however, if there are only warnings or no schema was specified, it can be TRUE and there will still be messages produced.

  2. Call XMLValidationError() to store the errors and warnings in a vector.

  3. Use VecSize() to find how many errors/warnings are in the vector

  4. Use a BlockWhile loop to read the vector. Here you can give the messages to the user one at a time in a warning box, as in our example, or store them in a table to view all at once.

You can also create a global function to handle validation errors, as shown in How Do I Retrieve Validation Errors of an XML Document?.

XMLValidate() syntax

The syntax of XMLValidate() is:

XMLValidate(XMLBLOB, [XSDSchema])

  • XMLBLOB is a BLOB containing the XML.

  • XSDSchema is the location of the schema, in URL format

Returns: It returns ‘FALSE’LOG if errors were found. It returns ‘TRUE’LOG if there were no errors, or if only warnings were found.

See also

How Do I Retrieve Validation Errors of an XML Document?

The Online and Rich Client Samples projects (program XM11 and RXM11)

Reference
Attachment 
Attachment