I have an images sitemap xml file and I am trying to validate it against a schema using Java code:
URL schemaFile = new URL("https://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd");
Source xmlFile = new StreamSource(new File("web.xml"));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);
and the XML:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>https://company.com/abc/is/images/A/AA/AAA/AAAA/A/product-name</loc>
<image:image>
<image:loc>https://company.com/abc/is/image//images/A/AA/AAA/AAAA</image:loc>
</image:image>
</url>
The Java validation error I receive is:
line: 2
column: 123
message: Cannot find the declaration of element 'urlset'.