Xsd验证 [英] Xsd validation

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

问题描述



我有一个简单的xml,其中包含一个元素" Book"其中有3个属性作者,版本,价格。我需要为此创建一个xsd,条件是,如果版本是"免费",则价格属性不需要具有价值/价格属性,如果版本是"付费",则价格属性应该是十进制值。

下面提到的是示例xml文件。目前我使用.Net IDE创建xsd并使用自定义数据类型来定义它。我使用xs:choice来执行此操作,但因为它不支持属性而无法正常工作。

Hi,

        I've a simple xml with one element "Book" which have 3 attributes author, edition, price. I need to create an xsd for this based on condition that,
if edition is "free", the price attribute need not have value/price attribute need not be required, and if edition is "paid", the price attribute should be a decimal value.
 
        Below mentioned is the sample xml file. Currently I've used .Net IDE to create xsd and used custom datatype to define this. I used xs:choice to do this, but  was not working as it was not supporting attributes.

<? xml version = " 1.0 " encoding = " utf-8 " ?>
<
图书馆 xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " xsi:noNamespaceS chemaLocation = " sample.xsd " >

<?xml version="1.0" encoding="utf-8"?>
<
Library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="sample.xsd">

< Book name = " 示例书1 " author = " 示例作者1 " < font color ="#0000ff"size = 2> edition = < font size = 2>" free " 价格 = "" >< / Book >

<Book name="Sample book 1" author="Sample author 1" edition="free" price=""></Book>

< 预订 name = " 示例书2 " author = " 示例作者2 " edition = " ; 付费 " price = " ; 100.0 " >< / Book >

<Book name="Sample book 2" author="Sample author 2" edition="paid" price="100.0"></Book>

< / 图书馆 >

提前致谢...

</Library>

Thanks in advance...

推荐答案

您好Jereesh,

您可能想看看Schematron 。 Schematron允许您使用XPath表达式在XSD中指定其他约束。

您可以在此处找到介绍性文章:


Hi Jereesh,

You might want to have a look at Schematron. Schematron allows you to specify additional constraints in your XSD using XPath expressions.

You find introductary articles here:

  • http://xml.coverpages.org/schematron.html
  • http://msdn.microsoft.com/en-us/library/aa468554.aspx

问候,
divo

Regards,
divo


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

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