XML 路径语言 (XPath) 1.0
XPath 标准的使用贯穿于整个 InfoPath,包括用于自定义验证、XSLT 视图、结构化编辑以及脚本化 DOM。
InfoPath 具有三个验证级别。在编辑 XML 文档时,InfoPath 可根据关联的自定义架构确保文档始终有效。除了这种基于架构的验证以外,InfoPath 还允许您定义使用 XPath 的其他自定义验证规则。您还可以使用脚本编写来定义其他规则和业务逻辑。
作为使用 XPath 标准定义自定义验证的一个示例,假设在某个销售报表中,您要求 Price 字段中的值不能大于 Maximum Price 字段中的值。假设基本的 XML 数据如下:
<salesReport>
<customers>
<customer>
<price>1230.00</price>
</customer>
<sales>
<maxPrice>1000.00</maxPrice>
</sales>
</customers>
</salesReport>
您可以在 Price 字段上自动为自定义验证定义 XPath 表达式。自定义验证规则存储在表单模板的清单文件中。要定义该自定义验证,请在视图中选择 Price 字段,然后使用 Data Validation 对话框来选择 架构节点。然后,自定义验证的 XPath 表达式会自动且透明地进行构造,如下所示:
<xsf:customValidation>
<xsf:errorCondition match="/salesReport/customers" expressionContext="customer/price"
expression=". > ../../sales/maxPrice">
<xsf:errorMessage type="modeless" shortMessage="Price exceeds maximum"></xsf:errorMessage>
</xsf:errorCondition>
</xsf:customValidation>
Microsoft Office InfoPath中用XML标准
0
相关文章