针对两个用于Google图像站点地图的XSD验证XML
||
我有一个XML文件(使用Google的
<image:image>
扩展名的站点地图),需要针对两个本地XSD文件进行验证,但是验证失败,因为<url>
不允许<image:image>
作为子级。完整的错误消息是
org.xml.sax.SAXParseException:
cvc-complex-type.2.4.a: Invalid content was found starting with element \'image:image\'.
One of \'{\"http://www.sitemaps.org/schemas/sitemap/0.9\":lastmod,
\"http://www.sitemaps.org/schemas/sitemap/0.9\":changefreq,
\"http://www.sitemaps.org/schemas/sitemap/0.9\":priority}\'
is expected.
这是我正在尝试验证的站点地图XML:
<?xml version=\"1.0\"?>
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\">
<url>
<loc>http://example.com/index.html</loc>
<image:image>
<image:loc>http://example.com/images/mysite.jpg</image:loc>
<image:title>My Site\'s Logo</image:title>
<image:caption>Logo for My Site by Andy Warhol (not really)</image:caption>
</image:image>
</url>
...
</urlset>
我将标准XSD用于站点地图和Google图片,但由于两者均未相互引用,因此我看不到如何使“ 0”成为“ 1”的有效子代。
如果有帮助,这里是执行验证的代码。
Source document = ...
StreamSource[] source = new StreamSource[] {
new StreamSource(this.getClass().getResourceAsStream(\"sitemap.xsd\"), \"http://www.sitemaps.org/schemas/sitemap/0.9\"),
new StreamSource(this.getClass().getResourceAsStream(\"sitemap-image.xsd\"), \"http://www.google.com/schemas/sitemap-image/1.1\")
};
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(source)
.newValidator().validate(document);
我能找到的最接近的SO问题需要预先解析和拆分XML文件,因为要应用的架构根据数据值而有所不同。我的要求要简单得多,希望可以更轻松地解决。
更新:我有一个旧的架构,不允许该元素有任何其他子代。 sitemaps.org已更新其XSD以添加
<xsd:any namespace=\"##other\" minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"strict\"/>
没有找到相关结果
已邀请:
2 个回复
僻朵庙惩竣
漂汀拦