🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators XmlValidateWithSchemas
This page was created by Hans.karlsen on 2021-08-17. Last edited by Wikiadmin on 2026-07-29.

You can use XmlValidateWithSchemas in an OCL expression to validate an XML string against one or more XML Schema (XSD) documents and process the reported validation messages.

Validate XML against schemas

Call the operator on selfVM, supply the XML to validate, and supply a collection of schema URLs.

selfVM.XmlValidateWithSchemas(xmlString, schemaUrls)
Argument Description
xmlString The XML text that you want to validate.
schemaUrls A collection containing one or more URLs to XML Schema (XSD) documents.

The operator reads the supplied schemas and returns validation output as strings. Each returned string is a message that you can store, display, or otherwise handle in your expression.

Example

The following expression validates <root/> against the supplied schema. It creates a Detail object for every returned message and stores the message in Attribute1.

selfVM.XmlValidateWithSchemas(
  '<root/>',
  Set{'http://www.gdsregistry.org/3.1/schemas/gs1/gdsn/CatalogueItemNotification.xsd'}
)->foreach(s |
  self.Details.Add(Detail.Create);
  self.Details->last.Attribute1 := s
)

In this example:

  • Set{...} supplies a collection with one schema URL. Add additional URLs to the collection when the XML must be validated with more than one schema.
  • s is one returned validation message.
  • The foreach expression records every message in self.Details, so the user can inspect the validation result.

Interpret the output

Validation output can contain errors and warnings. For example:

Error: The 'gtin' element is invalid - The value '' is invalid according to its datatype 'urn:gs1:shared:shared_common:xsd:3:GTINType' - The Pattern constraint failed.
Warning: No schema for root element.
Output type Meaning in the example
Error The gtin element has an empty value that does not satisfy the pattern required by GTINType.
Warning No supplied schema was found for the XML root element.

Use the complete returned message when presenting validation feedback. The message identifies the XML element and the schema rule that caused the result.

Use with generated XML

If you create XML from a ViewModel, generate the XML first and then pass the resulting string to XmlValidateWithSchemas. For ViewModel XML structure and XML-related tagged values, see Documentation:OCLOperators ViewModelAsXml.

See also