Mateusz Chromiński
Mateusz Chromiński

Reputation: 2832

XSD schema defining only attributes

In framework, which I write my application there are many xml files, in which node names doesn't really matter. All valuable information is placed in attributes. Node type is defined via one of the attribute.

I would like to write simple schema for this files. I think it should fulfill two major conditions:

if there will be possibility to make attributes list dependent on some given (e.g. type) argument it will be highly usefull.

Can XSD files handle these xml files? Is it possible to write such schema? How to define attributes list of any node.

Upvotes: 1

Views: 264

Answers (1)

Michael Kay
Michael Kay

Reputation: 163625

You can have a schema that defines only a complexType, with all the attributes. Your challenge then is to find a schema processor whose API allows you to request validation of a given input element against that named type. One way to do this is with a schema-aware XSLT processor:

<xsl:template match="*">
  <xsl:copy-of select="." type="my-complex-type"/>
  <xsl:apply-templates/>
</xsl:template>

will validate every element in the document against your type declaration (and produce a lot of output, which you can discard.)

Upvotes: 0

Related Questions