当前位置: 首页 > 知识库问答 >
问题:

XSD未针对xml进行验证

艾俊晖
2023-03-14

我是XSD新手,不知道为什么我的XSD没有进行验证。我收到以下错误:

s4s-elt-无效-内容.1:“参数信息”的内容无效。元素“复杂类型”无效、放错位置或出现过于频繁。

cvc复合型。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>    

我错过了什么吗?我想通过使用复杂类型并引用它们来分解它,从而使其更容易...

共有1个答案

狄宏大
2023-03-14

类型声明的参数信息如下

<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的教程。

 类似资料:
  • 问题内容: 我需要使用给定的XSD文件验证XML文件。我只需要如果验证正常就返回true,否则返回false的方法。 问题答案: 仅返回true或false(也不需要任何外部库):

  • 我有一个servlet,它使用打包在.jar存档中的实用程序: 此实用工具获取xml文件流,针对xsd模式执行验证并解析它: xsd文件以: xml文件: Servlet Init方法抛出异常: 如何指定SAXParser在哪里需要xsd模式来验证xml文件? 附注。对不起,我的英语不好 UPD: 我正在尝试添加此属性: UPD2:在xml文件中使用“classpath:appcontext.xs

  • 问题内容: 但是,这将返回一条错误消息:线程“ main”中的异常java.lang.IllegalArgumentException:无法加载实现由http://www.w3.org/2001/XMLSchema -instance 指定的模式语言的SchemaFactory。 这是我的代码还是实际的xsd文件有问题? 问题答案: 该错误意味着您安装的Java没有任何可解析XMLSchema文件

  • 我的目标是读取CSV文件,将其转换为XML,并根据XSD对其进行验证。代码如下: 错误: 线程“main”组织中出现异常。阿帕奇。骆驼FailedToCreateRouteException:无法在以下位置创建路由1: 此外,我还想配置如果XML对给定的XSD无效,是否会发生异常。我们如何配置它? 请好心帮忙。

  • 问题内容: 我有一个XML文件,并且有一个XML模式。我想针对该架构验证文件,并检查其是否符合该架构。我正在使用python,但是如果python中没有这样有用的库,则可以使用任何语言。 我在这里最好的选择是什么?我会担心如何快速启动和运行它。 问题答案: 绝对可以。 使用预定义的架构定义,加载文件并捕获任何XML架构错误: 关于编码的注意事项 如果模式文件包含带有编码(例如)的xml标记,则上面

  • 我试图根据内部引用另一个XSD的XSD验证XML(使用include语句)。 作为, 现在,当根据xsd(Schema1.xsd)验证我的XML时,如下所示: 我得到一个错误,“cvc-datatype-valid.1.2.1:'true'不是'boolean'的有效值。” 这是针对schema1.xsd引用的schema2.xsd中定义的元素。 如果我做错了什么,请告诉我。