gpt4 book ai didi

java - XSD - 如何定义两个元素之间的关系

转载 作者:数据小太阳 更新时间:2023-10-29 01:58:40 25 4
gpt4 key购买 nike

我有一个如下所示的 XSD 文件:

<element name="finder-def" minOccurs="0" maxOccurs="unbounded">
<complexType>
<attribute name="name" type="string" use="required"></attribute>
<attribute name="description" type="string"></attribute>
<attribute name="class" type="string" use="required"></attribute>
</complexType>
</element>

<complexType name="Dimension">
<sequence>
<element name="finder" type="Finder" minOccurs="0" maxOccurs="1"/>
</sequence>
</complexType>

<complexType name="Finder">
<attribute name="name" type="String" use="required"/>
</complexType>

XSD文件对应的XML文件如下:

<finder-def name="circleFinder" description="Finds circle based on msisdn" class="com.onmobile.reporting.etl.processor.common.propertyplugins.CircleIdPropertyPlugin" />

<dimension name="circleId">
<finder name="circleFinder" />
</dimension>

所以,我在这里定义了一个 finder-defcircleFinder 然后想通过 引用这个 finder-def finder 元素。

所以问题是如何验证 finder circleFinderfinder-def 中定义了上面的定义

最佳答案

只是另一种在模式中使用 ID 和 IDREF 类型的方法。例子:示例 XML:

<?xml version="1.0" encoding="UTF-8"?>
<f:root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:f="http://test.com/finder" xsi:schemaLocation="http://test.com/finder finder.xsd">

<f:finder-def name="circleFinder" description="Finds circle based on msisdn"
class="com.onmobile.reporting.etl.processor.common.propertyplugins.CircleIdPropertyPlugin"/>

<f:dimension name="circleId">
<f:finder name="circleFinder"/>
</f:dimension>
</f:root>

XSD 架构(我对其进行了一些格式化以进行验证)

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test.com/finder"
xmlns:tns="http://test.com/finder"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="finder-def" type="tns:finder-def" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="dimension" type="tns:Dimension" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="finder-def">
<xsd:attribute name="name" type="xsd:ID" use="required"/>
<xsd:attribute name="description" type="xsd:string"/>
<xsd:attribute name="class" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="Dimension">
<xsd:sequence>
<xsd:element name="finder" type="tns:Finder" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="Finder">
<xsd:attribute name="name" type="xsd:IDREF" use="required"/>
</xsd:complexType>
</xsd:schema>

关于java - XSD - 如何定义两个元素之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8047816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com