XSLT 转换期间 XSD 上的 XML 验证 [英] XML validation on XSD during XSLT transformation

查看:34
本文介绍了XSLT 转换期间 XSD 上的 XML 验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的代码来用 xslt 转换 xml 文件

I have this simple code to transform xml file with xslt

XslCompiledTransform transform = new XslCompiledTransform(true);
transform.Load("XSLTFile1.xslt", new XsltSettings(true, true), null);
XmlReader input = XmlReader.Create("XMLFile1.xml");
XmlWriter output = XmlWriter.Create("Result.xml", transform.OutputSettings);
transform.Transform(input, null, output);

如何在 XSD 上 xslt 转换期间验证我的输出 xml 文件?例如:如果 xslt 尝试创建另一个明确的标记(具有相同的名称)并且 XSD 不允许 - xslt 转换器将不会这样做(或产生异常)

How can I verify my output xml file on XSD during xslt transformation? for example: if xslt tries to make another definite tag (with the same name) and XSD don't allow it - xslt transformator will not do it (or generates exception)

推荐答案

XSLT 1.0 不支持模式.没有兼容的 XSLT 1.0 处理器有任何工具来指定所需输出的模式和验证输出.因此,XSLT 程序员只能在转换之后执行验证作为第二步.

XSLT 1.0 is not schema-aware. No compliant XSLT 1.0 processor has any facility for specifying the schema for the desired output and for validationg the output. Therefore, the XSLT programmer can perform the validation only as a second step, following the transformation.

XSLT 2.0 指定了模式感知 (SA) XSLT 2.0 处理器的特性,正是这种特性.SA 还可以验证使用 document() 函数获得的参数、变量、中间(临时)树和文档的类型.

XSLT 2.0 specifies the features of a schema-aware (SA) XSLT 2.0 processor that allows exactly this. SA can also validate the type of parameters, variables, intermediate (temporary) trees and documents obtained using the document() function.

一些著名的 XSLT 2.0 SA 处理器是 Saxon 9.x、XQSharp 和 AltovaXML.至少还有另外两个——IBM(WebSphere 的一部分)和英特尔.

Some well-known XSLT 2.0 SA processors are Saxon 9.x, XQSharp and AltovaXML. There are at least two other -- IBM's (part of WebSphere) and Intel's.

这篇关于XSLT 转换期间 XSD 上的 XML 验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆