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

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

我有以下包含内部 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 引用.XSD不能在内部使用是真的吗?

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) 您什么时候有过只描述单个实例文档的模式?Schema 本质上定义了文档类,而这些类很少是单例的.

(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.

更多推荐

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

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

发布评论

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

>www.elefans.com

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