我是XSD的新手,无法弄清楚为什么我的XSD无法验证。我收到以下错误:
s4s-elt-invalid-content.1:" parametersInfo'的内容是无效的。元素' complexType'无效,错位或过于频繁发生。
cvc-complex-type.2.4.d:找到以元素' exception'开头的无效内容。此时不会有子元素。
XML:
<?xml version="1.0" encoding="UTF-8"?>
<service id="IServiceREST">
<inherit>
<parent>Remote</parent>
</inherit>
<package>com.module</package>
<include>java.rmi.Remote</include>
<include>java.net.*</include>
<include>java.io.*</include>
<abstract_method id="getContent">
<visibility>public</visibility>
<parameters>
<argument type="URL">url</argument>
<argument type="int">timeout</argument>
</parameters>
<throw>
<exception>MalformedURLException</exception>
<exception>IOException</exception>
</throw>
<return>String</return>
</abstract_method>
<abstract_method id="deleteUser">
<visibility>public</visibility>
<parameters>
<argument type="String">username</argument>
</parameters>
<return>void</return>
</abstract_method>
</service>
XSD:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="serviceInfo">
<xs:sequence>
<xs:element name="inherit" type="inheritInfo" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="package" type="xs:string" />
<xs:element name="include" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="abstract_method" type="abstract_methodInfo" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute type="xs:string" name="id" />
</xs:complexType>
<xs:complexType name="inheritInfo">
<xs:sequence>
<xs:element type="xs:string" name="parent" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="abstract_methodInfo">
<xs:sequence>
<xs:element type="xs:string" name="visibility" minOccurs="0" maxOccurs="1"/>
<xs:element type="parametersInfo" name="parameters" />
<xs:element type="throwInfo" name="throw" minOccurs="0" maxOccurs="unbounded"/>
<xs:element type="xs:string" name="return" minOccurs="1" />
</xs:sequence>
<xs:attribute type="xs:string" name="id" />
</xs:complexType>
<xs:complexType name="throwInfo">
<xs:sequence>
<xs:element type="xs:string" name ="exception" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="parametersInfo">
<xs:complexType type="xs:string" name="argument">
<xs:sequence>
<xs:element name="URL" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="timeout" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:complexType>
<xs:element name="service" type="serviceInfo"/>
</xs:schema>
我错过了什么吗?我希望通过使用复杂类型并引用它们来简化它...
答案 0 :(得分:0)
您的parametersInfo
类型声明读取
<xs:complexType name="parametersInfo">
<xs:complexType type="xs:string" name="argument">
<xs:sequence>
<xs:element name="URL" type="xs:string"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="timeout" type="xs:integer"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:complexType>
XSD complexType
元素不能显示为complexType
的子元素。我不知道你要做什么,但这不是这样做的方法。
您可能需要在XSD上完成一两个教程。