0

我的 XSD 如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="AppRegisterConfig">
    <xs:sequence>
        <xs:element name="restServiceUrl" type="xs:string" />
        <xs:element name="timeout" type="xs:int" />
        <xs:element name="attempts" type="xs:int" />
    </xs:sequence>
</xs:complexType>

我的 XML 如下:

<?xml version="1.0" encoding="UTF-8"?>
<appregister-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:noNamespaceSchemaLocation="appregister-config.xsd">

  <restServiceUrl><url>url 1</url></restServiceUrl>
  <timeout>15000</timeout>
  <attempts>5</attempts>  
</appregister-config>  

知道我可能错过了什么吗?

4

1 回答 1

2

你还没有说你是如何调用验证的,但默认情况下,模式处理器会在模式中查找与源文档中最外层元素名称匹配的元素声明,如果找不到,它会告诉你所以。这就是这里发生的事情。

我希望看到

<xs:element name="appregister-config" type="AppRegisterConfig"/>

在您的架构中。

于 2013-06-12T08:22:30.780 回答