简体   繁体   English

我们如何在 XSD 中定义任何函数或任何可能的逻辑? 需要在 XSD 中验证 XML 文件的可能性

[英]How can we define any function in XSD or any logic is that possible? Need possibilities in XSD for validation of XML file

Sample XSD file for reference供参考的示例 XSD 文件

I want to know whether can we define any function or any encryption/decryption logic in xsd or list of what special features xsd can support?我想知道我们是否可以在 xsd 中定义任何函数或任何加密/解密逻辑或 xsd 可以支持哪些特殊功能的列表?

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" />
<xs:element name="address" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

No, this is not possible.不,这是不可能的。 XML schema is declarative and doesn't provide a facility to specify imperative logic or what most people would recognise as "code". XML 模式是声明性的,不提供指定命令式逻辑或大多数人会识别为“代码”的工具。 The set of features provided by XML schema is best summarised by its specification XML 模式提供的功能集最好由其规范概括

You haven't stated your actual requirement (what is the validation rule you want to impose?).您还没有说明您的实际要求(您要强加的验证规则是什么?)。 XSD 1.1 allows you to define assertions using XPath, including the full XPath function library; XSD 1.1 允许您使用 XPath 定义断言,包括完整的 XPath 函数库; and a particular implementation of XSD 1.1 may allow those XPath expressions to call out to extensions written in a procedural language like Java.并且 XSD 1.1 的特定实现可能允许这些 XPath 表达式调用用 Java 等过程语言编写的扩展。

So if you're using pure XSD 1.0 then the answer is no, but if you're prepared to adopt a solution that only works with Saxon (say), then the answer becomes yes.因此,如果您使用的是纯 XSD 1.0,那么答案是否定的,但是如果您准备采用仅适用于 Saxon(例如)的解决方案,那么答案就变成了是。

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

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