使用XSD验证XML有什么好处 [英] What is the advantage of validating XML with XSD

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

问题描述

你能告诉我在什么情况下我们根据XSD验证XML,


当我们从xml和xml创建XSD然后验证目的是什么时


你能告诉我一个实际的例子,

解决方案

例如,如果你使用XML来交换一些数据然后,您可以定义数据的结构以及元素和/或属性值的类型。如果我们交换例如。



< root> 
< foo>
< bar> 2010-03-31T13:32:00Z< / bar>
< / foo>
< / root>


然后没有架构,'bar'值只有字符串内容,如果字符串不正确,XML解析器不会标记错误dateTime格式。使用模式和验证XML解析器,如果'bar'元素的内容不是dateTime格式,解析器可以标记错误。


 


could you tell me in what cases we validate an XML against XSD,

when we create and XSD from and xml and then validate what is the purpose

could you tell me a practical example,

解决方案

For instance if you are using XML to exchange some data then you can define the structure of the data and the type of element and/or attribute values. If we exchange e.g.

<root>
  <foo>
    <bar>2010-03-31T13:32:00Z</bar>
  </foo>
</root>

then without a schema the 'bar' value simply has string contents and the XML parser will not flag an error if that string is not in the proper dateTime format. With a schema and a validating XML parser the parser can flag an error if the contents of the 'bar' element is not in the dateTime format.

 


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

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