"extend" the xml schema

I am trying to "extend" the xml schema (here for example nhibernate) to add my own objects to it. I'm sticking to the point where validation throttles the "exm: foo" object (and exm: foobar), since the "base" schema doesn't allow it. How can I do this without changing the base schema?

Example:

<?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


source to share


2 answers


Ideally, the schema allows you to expand at selected locations via xs: any ads. Unfortunately, the nhibernate schema doesn't.

So, you will have to write your own schema and import the existing schema. With this approach, you can derive new schema types from existing base schema types. Unfortunately class

nhibernate is defined with an anonymous type, which you cannot extend. So you will need to define your own class member and copy the nhibernate content model, extending it as desired.



As a consequence, applications that handle the underlying schema will probably not be able to handle your extended schema, so you will have to rewrite all the tools as well.

+2


source


You can use tags <meta>

to add additional information to NHibernate mapping files. This is a rarely used and poorly documented feature.

Documentation (for generating Hibernate Java code, but it can be used for anything else)

Mapping:



<class name="Post" table="POSTS" xmlns="urn:nhibernate-mapping-2.2" >
  <meta attribut="bar">baz</meta>

  <property name="Body" type="String" column="BODY">
    <meta attribute="property-bar">property-baz</meta>
  </property>

  <!-- ... -->
</class>

      

You can read the meta tags from the config

foreach (PersistentClass persistentClass in Configuration.ClassMappings())
{
  MetaAttributes attribute = persistentClass.GetMetaAttribute("bar");
  // ...
  foreach(Property property in persistentClass.PropertyIterator())
  {
    MetaAttributes propertyAttribute = property.GetMetaAttribute("property-bar");
    // ...
  }
}

      

0


source







All Articles