如何设计属性与内容模型具有排斥性约束的Schema?

carylin 2010-01-15 10:35:07
如何设计属性与内容模型具有排斥性约束的Schema文档?
举个例子,假设这是两份份满足Schema语法的XML示例文档:

<school>
<!-- global -->
<student id="1">
<name>Li Xiao Ming</name>
<age>7</age>
</student>
<monitor>
<!-- localReference -->
<student ref="1" />
</monitor>
</school>



<school>
<monitor>
<!-- local -->
<student>
<name>Wang Gang</name>
<age>7</age>
</student>
</monitor>
</school>

这里的student元素有三种格式:分别是全局的、局部的和局部引用的(分别标注上了global、local和localReference)。
monitor元素的内容模型既可以是local student元素,也可以是localReference student元素。student具有一个id属性,一个ref属性,一个有name与age组成的内容模型。而id属性与ref属性以及内容模型都有排斥性,ref属性又与内容模型具有排斥性。我没该如何设计Schema文档以满足这里的约束?

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/test"
xmlns:tns="http://www.example.org/test" elementFormDefault="qualified">
<xsd:element name="school">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="student" type="tns:GlobalStudentType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="monitor">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="student" type="tns:InnerStudentType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:complexType name="StudentType" abstract="true">
<xsd:sequence minOccurs="0">
<xsd:element name="name" type="xsd:string" />
<xsd:element name="age" type="xsd:unsignedShort" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="ref" type="xsd:IDREF" />
</xsd:complexType>

<xsd:complexType name="GlobalStudentType">
<xsd:complexContent>
<xsd:restriction base="tns:StudentType">
<xsd:sequence minOccurs="1">
<xsd:element name="name" type="xsd:string" />
<xsd:element name="age" type="xsd:unsignedShort" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="required" />
<xsd:attribute name="ref" type="xsd:IDREF" use="prohibited" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="LocalStudentType">
<xsd:complexContent>
<xsd:restriction base="tns:StudentType">
<xsd:sequence minOccurs="1">
<xsd:element name="name" type="xsd:string" />
<xsd:element name="age" type="xsd:unsignedShort" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="prohibited" />
<xsd:attribute name="ref" type="xsd:IDREF" use="prohibited" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="LocalRefStudentType">
<xsd:complexContent>
<xsd:restriction base="tns:StudentType">
<xsd:sequence minOccurs="0">
<xsd:element name="name" type="xsd:string" />
<xsd:element name="age" type="xsd:unsignedShort" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="prohibited" />
<xsd:attribute name="ref" type="xsd:IDREF" use="required" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="InnerStudentType">
<!-- How to designed this? Should LocalStudentType and LocalRefStudentType be used? -->
</xsd:complexType>

</xsd:schema>


如何通过LocalStudentType与LocalRefStudentType设计InnerStudentType?或是这里的方向不对?
...全文
203 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuahuilele 2010-01-18
  • 打赏
  • 举报
回复
不懂 顶了
carylin 2010-01-18
  • 打赏
  • 举报
回复
顶上去
carylin 2010-01-15
  • 打赏
  • 举报
回复
不是吧,都一天了,怎么还是没人解答?CSDN真是没落了。
carylin 2010-01-15
  • 打赏
  • 举报
回复
楼上的我也试过了,是不行的。定义在choice内的元素不能重名的。不过还是感谢。
reandyner 2010-01-15
  • 打赏
  • 举报
回复
<xsd:complexType name="InnerStudentType">
<xsd:complexContent>
<xsd:restriction base="tns:StudentType">
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="student" type="tns:LocalStudentType" />
<xsd:element name="student" type="tns:LocalRefStudentType" />
</xs:choice>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
哒哒路 2010-01-15
  • 打赏
  • 举报
回复
看不懂 帮顶
源码直接下载地址: https://pan.quark.cn/s/8ac6a8c064f8 Intellij Idea 12 外部jar包导入操作指南 Intellij Idea 12作为一款功能丰富且被广泛采纳的集成开发环境(IDE),为开发者提供了多种便利的工具以支持快速且高效的软件开发与调试工作。在众多功能中,从外部导入jar包是Intellij Idea 12的一项核心操作,接下来的内容将系统性地阐释如何在Intellij Idea 12环境中执行外部jar包的导入操作。 _步骤一:进入项目结构设置界面_ 启动Intellij Idea 12软件,加载一个既有的项目或新建一个项目,随后通过点击“文件”(File)菜单并从下拉选项中选择“项目结构”(Project Structure),此操作将引导用户进入项目结构配置界面。 _步骤二:执行模块添加流程_ 在呈现的项目结构配置界面中,用户需选择“模块”(Modules)这一选项卡,随后点击界面上的“+”符号,并从弹出的列表中选择“JARs or directories”(jar文件或目录),这一步骤将触发“添加jar或目录”(Add Jar or Directory)的对话框显示。 _步骤三:指定要导入的jar文件_ 在“添加jar或目录”(Add Jar or Directory)的对话框中,用户需要浏览并选中计划导入的jar文件,之后点击“确定”(OK)按钮,以完成jar文件的添加过程至项目中。 _步骤四:验证jar文件的导入状态_ 完成上述步骤后,用户可返回至项目结构配置界面,并在“依赖项”(Dependencies)选项卡下查看到新添加的jar文件,这证明了jar文件已成功被导入至项目中。 _注意事项_...

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧