2
votes

I am using XSD files to validate some XML files. One rule is that no script is allowed in the xml or specifically in this case xhtml document. I reckon that we need to specify in XSD file that no tag name = "script" is allowed in the entire document. How can this control be achieved?

As a beginner is XSD world I tried

      <xs:element name="script" maxOccurs="0"/>

but apparently it doesn't work.

1

1 Answers

1
votes

XSD 1.0

You cannot directly express the constraint that no script element may exist in the document, but you can omit script and allow it no way in: Simply do not use it in any the content models of any elements, and do not use xsd:any with lax or skip for @processContents.

XSD 1.1

In XSD 1.1 you can use xsd:assert to restrict xsd:any[@processContents='strict'] further (anywhere xsd:any is needed, or even for entire contents of the root element):

<xs:assert test="every $e in .//* satisfies $e[not(self::script)]"/>