微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

针对两个用于Google图像站点地图的XSD验证XML

如何解决针对两个用于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\"/>

解决方法

实际上,站点地图架构允许该位置的任何元素,只要它来自另一个名称空间,并提供周围的架构(因为\“ processContent \”是严格的。但是,您的数据无效,< caption>必须出现在之前。 当我在Java 1.6上对其进行测试时,它会验证确定。,花了我一段时间找出进行模式验证的语法(Google自己的示例实际上并未针对XSD文件进行验证): <code><pre><urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation= \"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"> </pre></code></div><ins class="adsbygoogle" style="display:inline-block;width:780px;height:90px" data-ad-client="ca-pub-4605373693034661" data-ad-slot="4286417769"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <p class="small text-muted">版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。</p> </div> </div> </div> </div> </div> <div class="col-sm-12 col-md-12 col-lg-3"> <!-- row --> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <!-- jb51-article-300x600 --> <ins class="adsbygoogle" style="display:inline-block;width:300px;height:600px" data-ad-client="ca-pub-4605373693034661" data-ad-slot="7541177540"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> </div> <!-- row end --> <!-- row --> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card" style="padding:20px;"> <label class="main-content-label ">小编推荐</label><div class="entry-img"><img src="https://www.jb51.cc/res/2023/06-29/12/fa513c17761076a6649593e2bd17f268.jpg" height="150" width="100%"><div class="entry-wrap"><a href="https://www.jb51.cc/mp/4606010.html" title="苹果市值2025年有望达4万亿美元" >苹果市值2025年有望达4万亿美元</a> </div></div><ul class="n-list"><li><a href="https://www.jb51.cc/mp/4821027.html" title="红魔10 Pro手机入网:电竞芯+6500mAh超大电池" >• 红魔10 Pro手机入网:电竞芯+6500mAh超</a></li><li><a href="https://www.jb51.cc/mp/4821026.html" title="iPhone 16系列价格最高直降1000元 保值力显著下降" >• iPhone 16系列价格最高直降1000元 保值</a></li><li><a href="https://www.jb51.cc/mp/4821025.html" title="文石Poke6电子书阅读器预售:支持TF卡拓展 899元起" >• 文石Poke6电子书阅读器预售:支持TF卡拓</a></li><li><a href="https://www.jb51.cc/mp/4821024.html" title="iPad mini 7仍维持20W快充标准:比亚迪代工" >• iPad mini 7仍维持20W快充标准:比亚迪</a></li><li><a href="https://www.jb51.cc/mp/4821023.html" title="吉利星座在轨卫星达30颗 可24小时覆盖全球90%区域" >• 吉利星座在轨卫星达30颗 可24小时覆盖全</a></li><li><a href="https://www.jb51.cc/mp/4821022.html" title="ColorOS 15发布 首发搭载OPPO Find X8和一加13" >• ColorOS 15发布 首发搭载OPPO Find X8和</a></li><li><a href="https://www.jb51.cc/mp/4821021.html" title="一加13外观曝光:首发第二代2K东方屏幕" >• 一加13外观曝光:首发第二代2K东方屏幕</a></li></ul> </div> </div> </div> <!-- row end --> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <label class="main-content-label ">热门标签<a href="https://www.jb51.cc/all" class="pull-right">更多</a> </label> <div class="topcard-tags"><a href="https://www.jb51.cc/tag/python/" title="python">python</a><a href="https://www.jb51.cc/tag/JavaScript/" title="JavaScript">JavaScript</a><a href="https://www.jb51.cc/tag/java/" title="java">java</a><a href="https://www.jb51.cc/tag/HTML/" title="HTML">HTML</a><a href="https://www.jb51.cc/tag/reactjs/" title="reactjs">reactjs</a><a href="https://www.jb51.cc/tag/C/" title="C#">C#</a><a href="https://www.jb51.cc/tag/Android/" title="Android">Android</a><a href="https://www.jb51.cc/tag/CSS/" title="CSS">CSS</a><a href="https://www.jb51.cc/tag/Nodejs/" title="Node.js">Node.js</a><a href="https://www.jb51.cc/tag/sql/" title="sql">sql</a><a href="https://www.jb51.cc/tag/rp/" title="r">r</a><a href="https://www.jb51.cc/tag/python3x/" title="python-3.x">python-3.x</a><a href="https://www.jb51.cc/tag/MysqL/" title="MysqL">MysqL</a><a href="https://www.jb51.cc/tag/jQuery/" title="jQuery">jQuery</a><a href="https://www.jb51.cc/tag/c4343/" title="c++">c++</a><a href="https://www.jb51.cc/tag/pandas/" title="pandas">pandas</a><a href="https://www.jb51.cc/tag/flutter/" title="Flutter">Flutter</a><a href="https://www.jb51.cc/tag/angular/" title="angular">angular</a><a href="https://www.jb51.cc/tag/IOS/" title="IOS">IOS</a><a href="https://www.jb51.cc/tag/django/" title="django">django</a><a href="https://www.jb51.cc/tag/linux/" title="linux">linux</a><a href="https://www.jb51.cc/tag/swift/" title="swift">swift</a><a href="https://www.jb51.cc/tag/typescript/" title="typescript">typescript</a><a href="https://www.jb51.cc/tag/luyouqi/" title="路由器">路由器</a><a href="https://www.jb51.cc/tag/JSON/" title="JSON">JSON</a><a href="https://www.jb51.cc/tag/luyouqishezhi/" title="路由器设置">路由器设置</a><a href="https://www.jb51.cc/tag/wuxianluyouqi/" title="无线路由器">无线路由器</a><a href="https://www.jb51.cc/tag/h3c/" title="h3c">h3c</a><a href="https://www.jb51.cc/tag/huasan/" title="华三">华三</a><a href="https://www.jb51.cc/tag/huasanluyouqishezhi/" title="华三路由器设置">华三路由器设置</a><a href="https://www.jb51.cc/tag/huasanluyouqi/" title="华三路由器">华三路由器</a><a href="https://www.jb51.cc/tag/diannaoruanjianjiaocheng/" title="电脑软件教程">电脑软件教程</a><a href="https://www.jb51.cc/tag/arrays/" title="arrays">arrays</a><a href="https://www.jb51.cc/tag/docker/" title="docker">docker</a><a href="https://www.jb51.cc/tag/ruanjiantuwenjiaocheng/" title="软件图文教程">软件图文教程</a><a href="https://www.jb51.cc/tag/C/" title="C">C</a><a href="https://www.jb51.cc/tag/vuejs/" title="vue.js">vue.js</a><a href="https://www.jb51.cc/tag/laravel/" title="laravel">laravel</a><a href="https://www.jb51.cc/tag/springboot/" title="spring-boot">spring-boot</a><a href="https://www.jb51.cc/tag/reactnative/" title="react-native">react-native</a></div> </div> </div> </div> </div> </div> </div> <footer id="footer"> <div class="container" style="width:1440px;"> <div class="row hidden-xs"> <div class="col-sm-12 col-md-9 col-lg-9 site-link"> <ul class="list-inline"> <li>友情链接:</li><li><a href="https://ai.jb51.cc/" title="ai导航是编程之家旗下ai方向的ai资讯、ai工具类集合导航站。" target="_blank" rel="nofollow">ai导航</a></li></ul> <ul class="list-inline"> <li><a href="https://www.jb51.cc" title="编程之家">编程之家</a></li>-<li><a href="https://t5m44pq3f7.jiandaoyun.com/f/638ca61b7b079a000a5d2dd6" rel="nofollow" title="我要投稿" target="_blank">我要投稿</a></li>-<li><a target="_blank" rel="nofollow" href="https://t5m44pq3f7.jiandaoyun.com/f/638ca8c69ad234000a79561f" title="广告合作">广告合作</a></li>-<li><a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=76874919&site=qq&menu=yes">联系我们</a></li>-<li><a href="https://www.jb51.cc/disclaimers.html" title="免责声明">免责声明</a></li>-<li><a href="https://www.jb51.cc/sitemap/all/index.xml" title="网站地图" target="_blank">网站地图</a></li> </ul> <div>版权所有 © 2018编程之家<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">闽ICP备13020303号-8</a> </div> </div> <div class="col-sm-12 col-md-3 col-lg-3"><img src="https://www.jb51.cc/qrcode.jpg" width="90" alt="微信公众号搜索 “ 程序精选 ” ,选择关注!"> <div class="pull-right">微信公众号搜<span class="text-danger">"智元新知"</span>关注<br />微信扫一扫可直接关注哦!</div> </div> </div> </div> </footer> <script src="https://www.jb51.cc/js/count.js"></script> </body> </html>