如何在XML Schema中使元素成为自己的子元素?
发布时间:2020-12-16 23:36:15 所属栏目:百科 来源:网络整理
导读:我希望能够拥有相同父元素的任意级别的嵌套子元素,例如: path expr="/" path expr="usr" path expr="bin" path expr="X11" / /path /path path expr="var" //path 我正在编写XML Schema文件,我不知道如何在模式中表示这种父/子关系:这是我所拥有的,但它不
|
我希望能够拥有相同父元素的任意级别的嵌套子元素,例如:
<path expr="/">
<path expr="usr">
<path expr="bin">
<path expr="X11" />
</path>
</path>
<path expr="var" />
</path>
我正在编写XML Schema文件,我不知道如何在模式中表示这种父/子关系:这是我所拥有的,但它不是一个有效的模式定义: <xs:element name="path">
<xs:complexType>
<xs:sequence>
<xs:element ref="path" minOccurs="0" />
</xs:sequence>
<xs:attribute name="expr" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
更新:感谢您的回复.我试过了,我收到以下错误:在此上下文中不支持’w3.org/2001/XMLSchema:complexType’元素.我应该提一下,我所描述的路径层次结构本身就是一个名为application的元素的子元素,因此整个结构类似于: <application name="test">
<path expr="/">
<path expr="usr">
<path expr="bin">
<path expr="X11" />
</path>
</path>
<path expr="var" />
</path>
</application>
解决方法
以下应该做的伎俩.
XSD标准很难直接使用,我总是使用像 Liquid XML Studio这样的编辑器. <?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML Studio - Developer Pro Edition 7.1.1.1206 (http://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Path" type="PathType" />
<xs:complexType name="PathType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Path" type="PathType" />
</xs:sequence>
<xs:attribute name="expr" type="xs:string" use="required" />
</xs:complexType>
</xs:schema>
alt text http://www.liquid-technologies.com/images/blogs/stackoverflow/PathExample.png XSD有效.对于您描述的新XML,您需要将其更改为如下所示. <?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML Studio - Developer Pro Edition 7.1.0.1135 (http://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Application">
<xs:complexType>
<xs:sequence>
<xs:element name="path" type="PathType" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:complexType name="PathType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="path" type="PathType" />
</xs:sequence>
<xs:attribute name="expr" type="xs:string" use="required" />
</xs:complexType>
</xs:schema>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
