Validating CDISC ODM Schema using R

This document outlines the steps that can be used to validate CDISC ODM files using the ODM standard Schema using R.

The XML schema used in this document is taken from CDISC ODM 1.3.2

First Example

The first demo is to validate this Sample ODM file with the ODM 1.3 schema.

  • The namespace of the ODM version was modified to ‘xmlns=“http://www.cdisc.org/ns/odm/v1.3”’
  • The validation result shows that this document is indeed conforms to CDISC ODM schema.
library(XML)
## Warning: package 'XML' was built under R version 3.2.3
xml.xsd = xmlSchemaParse("odm1_3_2/xml.xsd")
xmldsig.xsd = xmlSchemaParse("odm1_3_2/xmldsig-core-schema.xsd")
foundation.xsd = xmlSchemaParse("odm1_3_2/ODM1-3-2-foundation.xsd")
odm.xsd = xmlSchemaParse("odm1_3_2/ODM1-3-2.xsd")
odm.xml = xmlInternalTreeParse("odm1_3_2/odm-sample.xml")
v = xmlSchemaValidate(odm.xsd, odm.xml)
v
## $status
## [1] 0
## 
## $errors
## list()
## attr(,"class")
## [1] "XMLStructuredErrorList"
## 
## attr(,"class")
## [1] "XMLSchemaValidationResults"
  • Schema validation result: 0.

Second Example

This second example validates another ODM document CDISC_ODM_example_3.xml. The original document does not include any xml namespace. I had to modify the document by adding an ODM namespace (xmlns=“http://www.cdisc.org/ns/odm/v1.3”) to the file. As you can see the validation identified a number of errors.

odm.xml = xmlInternalTreeParse("odm1_3_2/CDISC_ODM_example_3.xml")
v = xmlSchemaValidate(odm.xsd, odm.xml)
v["status"]
## $status
## [1] 1824

Here are the 6 errors detected: