繁体   English   中英

是否可以将schematron模式编译为Biztalk程序集

[英]Is it possible to compile a schematron schema into a Biztalk assembly

是否可以创建schematron程序集,就像我们将.xsd模式编译为程序集并部署到Biztalk或其他应用程序一样(使用BTSCompile构建操作)?

例如,我们有一个基于HL7v3模式构建的常规程序集,而我有一个应用程序,可以从该程序集中将该模式作为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 Build Action对其进行编译,这是我假设必须能够“查看”程序集中的模式。

我现在使用的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模式不是很熟练,所以我可能忽略了一些简单的事情。

您可以通过使用xs:annotation元素将schematron规则嵌入XML模式中(就像Microsoft的BizTalk平面文件模式一样 )。 这将使您可以将schematron规则编译为BizTalk程序集。 此较早的MSDN文章中可以找到示例架构。

但是,BizTalk将忽略注释。 如果要利用这些规则,则需要告诉BizTalk如何做到这一点。

您可以编写一个自定义管道组件来执行schematron验证,也许依赖于Schematron.net库 或者,您可以使用开源管道组件,例如BizTalk的Schematron XmlValidator管道组件 (我自己没有使用过)。 如果您想编写一个用于验证整个xml文档的管道组件(而不是像第一个错误一样失败,默认的XML Validation组件也不例外),请查看Saravana Kumar 关于此事博客文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM