views:

200

answers:

1

I have an XML schema and an instance document I get from a customer. For example the document can be:

<doc>
   <carId>12</carId>
</doc>

And it is valid according to the schema.

I would like to annotate this with my attributes:

<doc>
   <carId myns:valid="true">12</carId>
</doc>

I would like the annotated document to be valid according to some schema - I don't care which schema, I guess it would be based on the original one.

My question is if there is some way to "extend" the original schema in a new schema without changing it? Alternatively is adding such attributes always legal provided that they are valid according their own schema?

I cannot assume anything about the original schema, i.e. it does not necessarily declare that xsd:anyAttribute is allowed on its elements.

A: 

This would be declared using xsd:anyattribute. It could either be left open to any attribute at all, restricted to a particular namespace, or (most commonly) permitted for any namespace other than one being defined right now).

One easy answer if you just want to check validity, and don't otherwise need schema data at runtime, is to remove your attributes from a copy and validate that.

It would also be fairly easy to generate a schema with the needed anyAttribute declarations for every complexType, deriving by extension, as long as the complexTypes have names, and the original schema did not use final to forbid this.

But if you truly have no control over the input schema, I don't see any option other than to modify it.

puetzk