我正在关注marklogic的教程,
https://developer.marklogic.com/learn/2007-04-schema
在一个场景中,我有 xsd 文件
<!-- tutorial.xsd -->
<xs:schema targetNamespace="http://marklogic.com/tutorial"
attributeFormDefault="unqualified"
elementFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="name" type="xs:token"
abstract="false" nillable="false"/>
<xs:element name="qualification" type="xs:token"
abstract="false" nillable="false"/>
<xs:element name="born" type="xs:date"
abstract="false" nillable="false"/>
<xs:element name="dead" type="xs:date"
abstract="false" nillable="false"/>
<xs:element name="isbn" type="xs:unsignedLong"
abstract="false" nillable="false"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="available" type="xs:boolean"/>
<xs:attribute name="lang" type="xs:language"/>
<xs:element name="title" abstract="false" nillable="false">
<xs:complexType mixed="false">
<xs:simpleContent>
<xs:extension base="xs:token">
<xs:attribute ref="lang" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="library" abstract="false" nillable="false">
<xs:complexType mixed="false">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="book" maxOccurs="unbounded" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="author" abstract="false" nillable="false">
<xs:complexType mixed="false">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="name" minOccurs="1" maxOccurs="1"/>
<xs:element ref="born" minOccurs="1" maxOccurs="1"/>
<xs:element ref="dead" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute ref="id" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="book" abstract="false" nillable="false">
<xs:complexType mixed="false">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="isbn" minOccurs="1" maxOccurs="1"/>
<xs:element ref="title" minOccurs="1" maxOccurs="1"/>
<xs:element ref="author" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="character" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="id" use="optional"/>
<xs:attribute ref="available" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="character" abstract="false" nillable="false">
<xs:complexType mixed="false">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="name" minOccurs="1" maxOccurs="1"/>
<xs:element ref="born" minOccurs="1" maxOccurs="1"/>
<xs:element ref="qualification" minOccurs="1"
maxOccurs="1"/>
</xs:sequence>
<xs:attribute ref="id" use="optional"/>
</xs:complexType>
</xs:element>
</xs:schema>
我想从此 xsd 中提取属性名称和类型。以下是我的 XQuery:
if (xdmp:database-name(xdmp:database()) ne 'Schemas')
then error(
QName('', 'NOT-SCHEMAS'), 'make sure the content-source is Schemas')
else
doc('tutorial.xsd')
/descendant::xs:element/@name
(: results :)
我得到以下信息:
name
qualification
born
dead
isbn
title
library
author
book
character
但我需要属性和值一起
name xs:token
qualification xs:token
born xs:token
有人可以帮我重写 Xquery 以实现上述输出吗?