Is it possible to create schematron assemblies, the same way we can compile .xsd schemas into assemblies and deploy to a Biztalk, or other application (using the BTSCompile build action)?
For example we have a regular assembly that was built from the HL7v3 schemas and I have an app that loads the Schema as an XmlSchema from the assembly and uses it to validate XML against. It works fine in this case.
Here's a the basic idea of what I'm talking about:
public static XmlSchema LoadSchema(System.Type schemaType)
{
if (schemaType == null)
{
throw new NullReferenceException("schemaType cannot be null. Pass a valid object type.");
}
XmlSchema schema = new XmlSchema();
try
{
// Grabbing an Assembly that is loaded for the type we're after.
Assembly schemaAssembly = Assembly.GetAssembly(schemaType);
foreach (Type type in schemaAssembly.GetTypes())
{
if (typeof(SchemaBase).IsAssignableFrom(type) && !type.IsNested && type.Name == schemaType.Name)
{
schema = (Activator.CreateInstance(type) as SchemaBase).Schema;
break;
}
}
}
catch (Exception ex)
{
throw new Exception("Could not Load Schema assembly.", ex);
}
return schema;
}
However, if I try to do the same for a Schematron I cannot get it to compile using the BTSCompile Build Action which is what I'm assuming is required to be able to "see" the schemas within the assembly.
The Schematron file I'm using is basically this for now:
<?xml version="1.0" encoding="utf-8"?>
<schema xmlns="http://www.ascc.net/xml/schematron" xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ascc.net/xml/schematron http://www.ascc.net/xml/schematron/schematron1-5.xsd" xmlns:hl7="urn:hl7-org:v3">
<title>Schematron Rule Definitions</title>
<ns uri="urn:hl7-org:v3" prefix="hl7"/>
<ns uri="http://www.w3.org/2001/XMLSchema-instance" prefix="xsi"/>
<!-- Rules that pertain to multiple sections of the CDA -->
<pattern name="Header - Test">
<rule context="/">
<assert test="hl7:ClinicalDocument">
ClinicalDocument must be the root node with the namespace urn:hl7-org:v3.
</assert>
</rule>
</pattern>
</schema>
The error I'm receiving when trying to compile is:
The root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.org/2001/XMLSchema'.
So, then when I do what it of course says:
The 'title' element is not supported in this context
because they aren't valid xml schema elements. So now my question is this: is there a way to do what I'm trying to do here? I'm not very proficient with XML Schemas, so it may be something simple I'm overlooking.