XSD验证错误:在xs:element中使用xs:any

时间:2017-09-12 07:39:41

标签: xml validation xsd

在我的XML架构中,我有以下定义:

<xs:element name="otherResultData">
    <xs:any processContents="lax" minOccurs="0" />
</xs:element>

这将给出验证错误:

  

'otherResultData'的内容必须匹配(注释?,(simpleType | complexType)?,(unique | key | keyref)*))。从以下问题开始发现问题:

有没有办法将其定义为:“这里可以有任何内容,但如果可以在此XSD中找到类型,那么它们是有效的”?

1 个答案:

答案 0 :(得分:1)

你需要像

这样的东西
CloseableHttpClient httpclient = HttpClients.createDefault();
ObjectMapper mapper = new ObjectMapper();
TestObj obj = new TestObj();
obj.setFile(IOUtils.toByteArray(new FileInputStream(new File("C:\\download.jpg"))));
obj.setMimetype("image/jpeg");
obj.setDescription("asd");
String jsonInString = mapper.writeValueAsString(obj);
HttpPost httpPost = new HttpPost("http://localhost:8080/url");
httpPost.setHeader("Authorization", "Bearer asdf");
httpPost.setHeader("Content-type", "application/json");
StringEntity se = new StringEntity(jsonInString);
httpPost.setEntity(se);
System.out.println(httpPost.toString());
CloseableHttpResponse response2 = httpclient.execute(httpPost);
try {
    System.out.println("!!!! " + jsonInString);
    System.out.println("!!!! " + se.toString());
    System.out.println("!!!! " + response2.getStatusLine());
    HttpEntity entity2 = response2.getEntity();
    EntityUtils.consume(entity2);
} finally {
    response2.close();
}