使用Marklogic时对XML模式进行版本控制

我在其他地方读过,在 XML模式的URL中使用版本字符串通常是不好的做法 – 出于我理解的原因.

我想知道在使用Marklogic DB时这个咒语是否仍然适用?我的理由是命名空间和存储的XML对象在Marklogic中看起来非常紧密.在这种情况下,通常建议将版本存储在XML内容中的方法似乎没那么有用,在这种情况下,您希望数据库引擎了解要使用的XSD架构版本.这告诉我,与流行的智慧相反,命名空间中的版本字符串可能是更好的方法.

我们的XSD的当前版本中没有版本,但是一旦我们将现有的XML文档导入并运行,我们还需要在几个月后创建一个增强版本

编辑 – 如果不是很明显,我是Marklogic的新手!

解决方法

另一种考虑版本控制的方法是使用xsi:schemaLocation来说明通过物理位置使用哪个版本的模式.

Schemas Database:

/schemas/versions/1.0/A.xsd
/schemas/versions/2.0/A.xsd

xsi:schemaLocation=”http://www.example.com/schemas/A /schemas/versions/1.0/A.xsd”

and

xsi:schemaLocation=”http://www.example.com/schemas/A /schemas/versions/2.0/A.xsd”

通过这种方式,MarkLogic将使用schemaLocation中定义的xsd进行索引和验证.

================================================== =======
编辑:为了扩展Mary的评论,上面的示例基于模式数据库,并显示完整路径.我没有说明.但是,就schemaLocation是完整路径而言,在某些情况下,您可能只需要导入一个模式.

以包裹中发布的模式为例:

/schemas/versions/3.0/A.xsd
/schemas/versions/3.0/common/something.xsd
/schemas/versions/3.0/common/something-else.xsd

想象一下,A.xsd在./common/something.xsd的import语句中
和something.xsd有一个./something-else.xsd的import语句

在这种情况下,只需为/schemas/versions/3.0/A.xsd定义schemaLocation即可,因为MarkLogic将相对于导入的模式导入另外两个.

================================================== =======
编辑2:已经提出了另一个问题.当使用SchemaLocation时,MarkLogic如何告诉您正在使用WHICH模式.答案是sc:xxxx函数.最基本的是xs:schema.在其他漂亮的东西中,它会告诉你该架构的架构和位置,因为它解决了它.使用的函数可用于任何元素.我只是在以下示例中使用文档本身:

模式加载到模式数据库中,目标名称空间为http://my/A/Namespace

/schemas/v3/A.xsd
/schemas/v4/A.xsd

schemaLocation设置为版本4的示例:

<document
xmlns="http://my/A/Namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://my/A/Namespace /schemas/v4/A.xsd"
>
<something>Bla Bla</something>
</document>/sc:schema()

结果:[164,http://my/A/Namespace at /schemas/v4/A.xsd ok]

schemaLocation设置为版本3的示例:

<document
xmlns="http://my/A/Namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://my/A/Namespace /schemas/v3/A.xsd"
>
<something>Bla Bla</something>
</document>/sc:schema()

结果:[164,http://my/A/Namespace at /schemas/v3/A.xsd ok]

schemaLocation未设置的示例:

<document
xmlns="http://my/A/Namespace"
>
<something>Bla Bla</something>
</document>/sc:schema()

结果:[164,http://my/A/Namespace at /schemas/v3/A.xsd ok]
在这个案例中,MarkLogic做出了选择……

schemaLocation设置为不存在的版本的示例:

<document
xmlns="http://my/A/Namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://my/A/Namespace /schemas/v9999/A.xsd"
>
<something>Bla Bla</something>
</document>/sc:schema()

结果:[108,http://my/A/Namespace at dummy ok]

在这种情况下,MarkLogic发现你非常调皮并且拒绝做出任何假设.如果你宣布一个schemLocation然后在那个位置没有xsd,MarkLogic将不会回归到自己找到一个..另外,因为它发现你的行为有点傻,它会回复你称你为假人..嗯..这个词可能有更多的技术原因,但我喜欢我的描述.

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念