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
The first demo is to validate this Sample ODM file with the ODM 1.3 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"
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:
In line 202, Element ‘{http://www.cdisc.org/ns/odm/v1.3}ItemDef’, attribute ‘SDSVarName’: [facet ‘maxLength’] The value ‘ABNORM SDS Variable Name’ has a length of ‘24’; this exceeds the allowed maximum length of ‘8’.
In line 202, Element ‘{http://www.cdisc.org/ns/odm/v1.3}ItemDef’, attribute ‘SDSVarName’: [facet ‘pattern’] The value ‘ABNORM SDS Variable Name’ is not accepted by the pattern ’[A-Za-z_][A-Za-z0-9_]*’.
In line 202, Element ‘{http://www.cdisc.org/ns/odm/v1.3}ItemDef’, attribute ‘SDSVarName’: ‘ABNORM SDS Variable Name’ is not a valid value of the atomic type ‘{http://www.cdisc.org/ns/odm/v1.3}sasName’.
In line 740, Element ‘{http://www.cdisc.org/ns/odm/v1.3}MetaDataVersionRef’, attribute ‘EffectiveDate’: ‘20011019T10:45:57-05:00’ is not a valid value of the atomic type ‘{http://www.cdisc.org/ns/odm/v1.3}date’.
In line 743, Element ‘{http://www.cdisc.org/ns/odm/v1.3}MetaDataVersionRef’, attribute ‘EffectiveDate’: ‘20011019T10:45:57-05:00’ is not a valid value of the atomic type ‘{http://www.cdisc.org/ns/odm/v1.3}date’.
In line 746, Element ‘{http://www.cdisc.org/ns/odm/v1.3}MetaDataVersionRef’, attribute ‘EffectiveDate’: ‘20011019T10:45:57-05:00’ is not a valid value of the atomic type ‘{http://www.cdisc.org/ns/odm/v1.3}date’.