我正在尝试为此架构编写有效的XML:
<xsd:complexType name="resourceType">
<annotation xmlns="http://www.w3.org/2001/XMLSchema">
<documentation>
A resource root within a deployment.
</documentation>
</annotation>
<xsd:all>
<xsd:element name="filter" type="filterType" minOccurs="0">
<annotation xmlns="http://www.w3.org/2001/XMLSchema">
<documentation>
A path filter specification for this resource root (optional). By default all paths are accepted.
</documentation>
</annotation>
</xsd:element>
</xsd:all>
<xsd:attribute name="name" type="xsd:string" use="optional">
<annotation xmlns="http://www.w3.org/2001/XMLSchema">
<documentation>
The name of this resource root (optional). If not specified, defaults to the value of the path
attribute.
</documentation>
</annotation>
</xsd:attribute>
<xsd:attribute name="path" type="xsd:string" use="required">
<annotation xmlns="http://www.w3.org/2001/XMLSchema">
<documentation>
The path of this resource root, relative to the path in which the module.xml file is found.
</documentation>
</annotation>
</xsd:attribute>
</xsd:complexType>
我是XML和XSD的新手,我将不胜感激:根据这个XSD,什么是一个有效的示例XML文档?
答案 0 :(得分:1)
有两个问题阻止任何XML对提供的XSD有效:
filterType
。将filterType
替换为xsd:string
并添加根元素,r
类型等于XSD中的顶级complexType,然后修改XSD,
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="r" type="resourceType"/>
<xsd:complexType name="resourceType">
<annotation xmlns="http://www.w3.org/2001/XMLSchema">
<documentation>
A resource root within a deployment.
</documentation>
</annotation>
<xsd:all>
<xsd:element name="filter" type="xsd:string" minOccurs="0">
<annotation xmlns="http://www.w3.org/2001/XMLSchema">
<documentation>
A path filter specification for this resource root
(optional). By default all paths are accepted.
</documentation>
</annotation>
</xsd:element>
</xsd:all>
<xsd:attribute name="name" type="xsd:string" use="optional">
<annotation xmlns="http://www.w3.org/2001/XMLSchema">
<documentation>
The name of this resource root (optional). If not specified,
defaults to the value of the path attribute.
</documentation>
</annotation>
</xsd:attribute>
<xsd:attribute name="path" type="xsd:string" use="required">
<annotation xmlns="http://www.w3.org/2001/XMLSchema">
<documentation>
The path of this resource root, relative to the path in
which the module.xml file is found.
</documentation>
</annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:schema>
将成功验证以下XML,例如:
<?xml version="1.0" encoding="UTF-8"?>
<r path="">
<filter/>
</r>