“扩展"一个xml模式 [英] "extend" an xml schema

查看:72
本文介绍了“扩展"一个xml模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试扩展"一个xml模式(例如在这里处于休眠状态),以在其中添加自己的实体. 我坚持认为验证在"exm:foo"(和exm:foobar)实体上很困难,因为基本"架构不允许这样做.如何在不更改基本架构的情况下做到这一点?

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 ?

样品:

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

推荐答案

理想情况下,模式可以通过xs:any声明允许在选定位置进行扩展.不幸的是,nhibernate模式没有.

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

因此,您将必须编写自己的架构,并导入现有架构.通过这种方法,您可以从现有的基本架构类型中派生新的架构类型.不幸的是,nhibernate的元素class是使用无法扩展的匿名类型定义的.因此,您将必须定义自己的类元素并复制nhibernate的内容模型,并在需要的地方进行扩展.

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.

这篇关于“扩展"一个xml模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆