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

标签 marklogic

我在别处读到使用版本字符串到 网址 XML 模式通常是不好的做法 - 出于我理解的原因。

我想知道这个咒语在使用 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 的评论,上面的示例基于 schemas 数据库并且还显示了完整路径。我没有这么说。但只要 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 的导入语句
并且 something.xsd 有一个 ./something-else.xsd 的导入语句

在这种情况下,可以只使用为/schemas/versions/3.0/A.xsd 定义的 schemaLocation,因为 MarkLogic 将相对于导入的模式导入其他两个。

================================================== ========
编辑 2:另一个问题已被问到。使用 SchemaLocation 时,您如何在 MarkLogic 中知道正在使用哪个模式。答案是 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/schemas/v4/A.xsd 好的]

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/schemas/v3/A.xsd 好的]

schemaLocation 为 的示例未设置 :
<document
xmlns="http://my/A/Namespace"
>
<something>Bla Bla</something>
</document>/sc:schema()

结果:[164, , http://my/A/Namespace/schemas/v3/A.xsd 好的]
在这种情况下,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假人好的]

在这种情况下,MarkLogic 发现您非常顽皮并拒绝做出任何假设。你的行为有点傻,它的回应是称你为傻瓜.. 嗯.. 傻瓜这个词可能有更技术性的原因,但我喜欢我的描述。

关于marklogic - 使用 Marklogic 时对 XML 模式进行版本控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32481005/

相关文章:

marklogic - 如何使用标记化来分解单词和数字

marklogic - 如何删除数据库中的所有数据?

javascript - MarkLogic:按属性值查找

marklogic - Marklogic Java 客户端 API 中的 exportListener 是否有压缩选项?

marklogic - if() 以一种奇怪的方式处理 bool 值

sparql - 有没有办法优化 SPARQL 查询?

java - MarkLogic 通配符搜索 - 控制台与 Java API

node.js - marklogic,如何创建文档属性范围

marklogic - 光学API : how do I get the value of a column that goes with a max value?

Xpath使用获取属性值