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

后端 未结 2 1138
清酒与你
清酒与你 2020-12-21 22:09

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




        
相关标签:
2条回答
  • 2020-12-21 22:24

    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.

    0 讨论(0)
  • 2020-12-21 22:28

    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.

    0 讨论(0)
提交回复
热议问题