I am processing a third party xml file and validating it against an xsd provided by the third party. Their xsd is incomplete (imo). For instance they have an attribute defined as follows:
<xsd:attribute name="debit_flag" type="string_1" use="required"></xsd:attribute>
But it can only have the value “1” or “0”:
<xs:element name="debit_flag_type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1"/>
<xs:enumeration value="0"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
I can’t change their xsd (as they might update it in the future) so can I add a second xsd schema from which I can add extra checks as above and will there be a major overhead?
Thanks,
Patrick
Your best option is, as always, to inform the third party of the inconsistencies in their schema. After all, if they use that schema to validate their data before they send it to you, there’s no use expanding on it, because the datatypes are guaranteed equal to the (limited) definitions in the schema.
However, XML Schema Definitions allow to import a schema. What you can do is write your own XSD that imports the schema of the third party using
<xsd:import />. Unfortunately, it depends on the definitions in the imported XSD whether or not you can indeed override them. In other words, even in this scenario, your options are limited.Testing your input data against two different schema’s: I wouldn’t do it. If your schema is widening definition (i.e., allows more) then it is useless in all scenarios. If it is a narrowing definition, it might have benefit, but only for your own application.