Is it possible to use XML Schemas internally, just like DTDs?

三世轮回 提交于 2019-11-29 16:50:22

In principle you can do:

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

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.

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

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

No, although you may find some ad hoc implementational support for embedding an XSD within an XML document instance, there is no standard mechanism for XSD that corresponds to DTD's internal subset.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!