简体   繁体   English

我正在尝试针对 XMLSchema(XSD)验证 XML,下面是我为我拥有的代码得到的错误。 我可以知道我哪里出错了吗?

[英]I am trying to validate XML against XMLSchema( XSD), below is the error I got for the code I have. May I know where I am going wrong?

Below is the code I have for validating XML file with XSD file.下面是我用 XSD 文件验证 XML 文件的代码。

public class XmlXsdValidation {

    public static void main(String[] args) {
        final String xsdPath = "D://tmp/xsdFile.xsd";
        final String xmlPath = "D://tmp/xmlFile.xml";

        File xsdFile = new File(xsdPath);
        File xmlFile = new File(xmlPath);

        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        try {
            javax.xml.validation.Schema xmlSchema = factory.newSchema(xsdFile);
            Validator validator = xmlSchema.newValidator();
            validator.validate(new StreamSource(xmlFile));
            System.out.println("Sucess....");
        } catch (IOException e) {
            e.printStackTrace();

        } catch (SAXException e) {
            e.printStackTrace();
        }

    }

}

Below is the xmlFile.xml content:以下是 xmlFile.xml 内容:

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  <s11:Body>
    <ns1:LanguageName xmlns:ns1='http://www.oorsprong.org/websamples.countryinfo'>
      <ns1:sISOCode>abk</ns1:sISOCode>
    </ns1:LanguageName>
  </s11:Body>
</s11:Envelope>

Below is the xsdFile.xsd content:下面是 xsdFile.xsd 内容:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" targetNamespace="http://schemas.xmlsoap.org/soap/envelope/" elementFormDefault="qualified">
    <xsd:element name="Envelope">
        <xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:element name="Body" minOccurs="0">
                    <xsd:complexType mixed="true">
                        <xsd:sequence>
                            <xsd:element name="LanguageNameResponse" minOccurs="0">
                                <xsd:complexType mixed="true">
                                    <xsd:sequence>
                                        <xsd:element name="LanguageNameResult" minOccurs="0" type="xsd:normalizedString" />
                                    </xsd:sequence>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

OutPut( Error message): file:/D:/tmp/xmlFile.xml;输出(错误消息):文件:/D:/tmp/xmlFile.xml; lineNumber: 3;行号:3; columnNumber: 83;列号:83; cvc-complex-type.2.4.a: Invalid content was found starting with element 'ns1:LanguageName'. cvc-complex-type.2.4.a:发现从元素“ns1:LanguageName”开始的无效内容。 One of '{"http://schemas.xmlsoap.org/soap/envelope/":LanguageNameResponse}' is expected. '{"http://schemas.xmlsoap.org/soap/envelope/":LanguageNameResponse}' 之一是预期的。

WSDL file considered: https://www.swi-prolog.org/pack/file_details/wsdl/examples/country.wsdl考虑的 WSDL 文件: https ://www.swi-prolog.org/pack/file_details/wsdl/examples/country.wsdl

The SOAP envelope and the SOAP body are in different namespaces. SOAP 信封和 SOAP 主体位于不同的名称空间中。 You need one schema document for each namespace, with appropriate xs:import links connecting them.您需要为每个命名空间创建一个模式文档,并使用适当的xs:import链接将它们连接起来。 Each element must be declared in the schema document with the correct targetNamespace .每个元素都必须在模式文档中用正确的targetNamespace声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我不知道BigIntegers出了什么问题 - I don't know where I am going wrong with BigIntegers 尝试导入课程时哪里出错了? - Where am I going wrong in trying to import a class? 这个菜单我哪里出错了 - Where am I going wrong with this menu Java程序:哪里出问题了? - Java Program: Where am I going wrong? 当针对XSD验证XML时,为什么会出现org.xml.sax.SAXParseException? - Why am I getting org.xml.sax.SAXParseException when validate XML against XSD? 我的代码遇到了运行时错误,有人可以帮我找出我哪里错了 - i got Runtime Error for my code ,can anyone help me to find out where i am wrong 我正在使用eclipse并收到此错误,有人可以告诉我我要去哪里了 - I am using eclipse and getting this error can someone tell me where I am going wrong 谁能告诉我代码中的错误或我在哪里出错? - Can anybody tell what error or where am i going wrong in code? 为什么 PlayIntegrity api 调用导致错误代码:GoogleServerUnavailable。 我哪里错了? - Why PlayIntegrity api call resulting in Error code : GoogleServerUnavailable. Where am i going wrong? 我正在尝试运行以下提到的代码,但出现错误 - I am trying to run the below mentioned code but getting an error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM