如何使用 Marklogic sc:annotations 方法访问模式元素注释

How to access schema element annotation using Marklogic sc:annotations method

给定以下架构

<?xml version="1.0" encoding="UTF-8"?>
<?xdmp-annotations all?> <!-- Preserve documentation annotations -->
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    elementFormDefault="qualified"
    targetNamespace="http://my-namespace/graphql" 
    xmlns:gql="http://my-namespace/graphql">

    <xs:complexType name="Person">
        <xs:choice maxOccurs="unbounded">
            <xs:element name="name" type="xs:string" minOccurs="1"/>
            <xs:element name="height" type="xs:string" minOccurs="0"/>
            <xs:element name="appearsIn" type="xs:string" minOccurs="0"/>
            <xs:element name="friends">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="person" type="gql:Person" maxOccurs="unbounded"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:choice>
    </xs:complexType>

    <xs:element name='person' type='gql:Person'>
        <xs:annotation>
            <xs:documentation>
            Person interface
            </xs:documentation>
        </xs:annotation>
    </xs:element>

</xs:schema>      

如何访问 "person" 元素文档?

下面的代码returns什么都没有:

xquery version "1.0-ml";

import schema namespace gql ="http://my-namespace/graphql" at "/graphql/person.xsd";

let $element := element {xs:QName('gql:person')} {}
return 
<xml>
  {sc:element-decl($element) => sc:annotations()}
</xml>

根据文档,处理指令“<?xdmp-annotations all?>”应该足以确保除了 appinfo 之外还返回文档,不是吗?

两件事:

  1. 您的命名空间在架构和查询之间不匹配,所以您得到的命名空间虚拟架构没有特定的元素声明,所以它被视为 anyType .
  2. 您需要将处理指令放在 xs:schema 元素中,以便模式解析代码能够看到它。

解决这两个问题,您的查询就可以正常工作了。