是否可以像DTD一样在内部使用XML模式?

编程入门 行业动态 更新时间:2024-10-23 18:27:54
本文介绍了是否可以像DTD一样在内部使用XML模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下包含内部DTD验证的XML文件:

I have the following XML file which includes internal DTD validation:

<?xml version="1.0"?> <!DOCTYPE animals [ <!ELEMENT animals (animal)*> <!ELEMENT animal (skin, noise, eyes, diet, class, weight, special_skill)> <!ELEMENT skin (#PCDATA)> <!ELEMENT noise (#PCDATA)> <!ELEMENT eyes (#PCDATA)> <!ELEMENT diet (#PCDATA)> <!ELEMENT class (#PCDATA)> <!ELEMENT weight (#PCDATA)> <!ELEMENT special_skill (#PCDATA)> <!ATTLIST animal name CDATA #REQUIRED > <!ATTLIST weight unit CDATA "kg"> ]> <animals> <animal name="cow"> <skin> Straight fur </skin> <noise> Moo! </noise> <eyes> 2 </eyes> <diet> Herbivore </diet> <class> Mammalia </class> <weight unit="kg"> 635-1134 </weight> <special_skill> Chewing </special_skill> </animal> <animal name="sheep"> ... </animal> </animals>

我一直在寻找如何用XSD替换DTD验证,但找不到任何示例。似乎XSD总是需要在单独的文件中定义,并由XML进行引用。

I was looking for how to replace the DTD validation with an XSD but couldn't find any examples. It seems like XSDs always need to be defined in a separate file and the be referenced by the XML. Is this true that XSD cannot be used internally?

推荐答案

原则上可以做到:

<package> <xs:schema id="XSD"> ... schema goes here ... </xs:schema> <doc xsi:noNamespaceSchemaLocation="#XSD"> ... instance goes here ... </doc> </package>

但是(a)不能保证任何特定的模式处理器都会支持这种形式的位置URI,并且(b)很难理解这一点。

But (a) there's no guarantee that any particular schema processor will support this form of location URI, and (b) it's hard to see the point.

我知道DTD已完成,但我从未真正理解过:

I know it's done with DTDs, but I've never really understood:

(i)如果您要验证文档,您肯定想知道它对哪种模式有效,而不是信任它来定义自己的模式吗?知道此文档对某些模式有效,但我不知道该模式中的内容有什么用?

(i) if you want to validate a document, surely you want to know what schema it's valid against, rather than trusting it to define its own? What use is it to know "this document is valid against some schema but I've no idea what's in that schema"?

(ii)您什么时候拥有一个仅描述单个实例文档的模式?模式按其性质定义文档的类,而这些类很少是单例。

(ii) when did you ever have a schema that described only a single instance document? Schemas by their nature define classes of document, and those classes are rarely singletons.

更多推荐

是否可以像DTD一样在内部使用XML模式?

本文发布于:2023-11-25 15:42:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在内部   模式   DTD   XML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!