I have a schema that I use to validate HTTP requests to my app. It works really well for the query string and post content, but I’ve hit a stumbling block with the header parameters. Ideally I’d like to check that HTTP_REQUEST_METHOD is ‘GET’ or ‘POST’ etc, but other than that, I don’t care what values the other parameters have.
So, my XML might look like:
<REQUEST>
<HEADERS>
<User-Agent>bla bla</User-Agent>
<Cookie>bla bla</Cookie>
...
<request_method>GET</request_method>
...
<remote_port>bla bla</remote_port>
</HEADERS>
<QUERY_STRING>
...
</QUERY_STRING>
</REQUEST>
Is there any means by which I can specify a wildcard for the header parameters that I can’t forsee, whilst insisting that if there’s a tag that its contents are fixed?
Sort of this:
<xsd:any namespace="##any" minOccurs="0" processContents="lax"/>
... fixed value of 'GET' for <request_method> ...
<xsd:any namespace="##any" minOccurs="0" processContents="lax"/>
That’s basically what
laxis for. It will validate elements it knows about and ignore others. You would just put a singleanyin you content model withmaxOccurs=unboundedand also define the known parameters likerequest_headeras global elements.The only catch is that any other defined global element will also be validated if it occurs there.
Example schema:
There are richer options in XML Schema 1.1 in case your validator has support for it.