是否可以创建schematron程序集,就像我们可以将.xsd模式编译为程序集并将其部署到Biztalk或其他应用程序一样(使用BTSCompile构建操作) ?是否可以将schematron模式编译为Biztalk程序集
例如,我们有一个从HL7v3模式构建的常规程序集,我有一个应用程序从程序集中加载Schema作为XmlSchema,并使用它来验证XML。在这种情况下它工作正常。
这里有一个什么我谈论的基本思想:
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;
}
但是,如果我尝试了Schematron的做同样的我不能让它使用BTSCompile生成操作而这正是编译我假设需要能够“查看”程序集中的模式。
我使用的Schematron的文件基本上是这样,现在:
<?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 root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.org/2001/XMLSchema'.
所以,后来当我做它当然说:
The 'title' element is not supported in this context
,因为它们不是有效的xml模式元素。所以现在我的问题是这样的:有没有办法做我想在这里做的事情?我对XML Schema不太熟练,所以它可能是我忽略的一些简单的东西。
我重新启动了XRouter SchemaTron并添加了XPath2/XSLT2支持。查看https://github.com/gap777/SchemaTron – gap