views:

75

answers:

1

I'm trying to "extend" an xml schema (nhibernate here, for example), to add my own entities inside of it. I'm stuck to the point where validation chokes on the "exm:foo" (and exm:foobar) entity, as the "base" schema doesn't allow it. How can I manage to do that, without changing the base schema ?

Sample :

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Test" namespace="Test.DataAccess.Entities" xmlns:exm="urn:extend-mappings">
  <class name="Post" table="POSTS" xmlns="urn:nhibernate-mapping-2.2" >
    <exm:foo bar="baz" />

    <property name="Body" type="String" column="BODY">
      <exm:foobar />
    </property>

    [...]

  </class>
</hibernate-mapping>
+2  A: 

Ideally, a schema would allow extensions in selected places, by means of xs:any declarations. Unfortunately, the nhibernate schema does not.

So you will have to write your own schema, and import the existing schema. In such an approach, you could derive new schema types from the existing base schema types. Unfortunately, the element class of nhibernate is defined using an anonymous type which you cannot extend. So you would have to define your own class element and copy nhibernate's content model, extending it where desired.

As a consequence, applications processing the base schema probably will not be able to process your extended schema, so you will also have to rewrite all tools.

Martin v. Löwis