久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

針對(duì)多個(gè)模式定義驗(yàn)證 XML 文件

Validate an XML File Against Multiple Schema Definitions(針對(duì)多個(gè)模式定義驗(yàn)證 XML 文件)
本文介紹了針對(duì)多個(gè)模式定義驗(yàn)證 XML 文件的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在嘗試針對(duì)許多不同的模式驗(yàn)證 XML 文件(為人為的示例道歉):

I'm trying to validate an XML file against a number of different schemas (apologies for the contrived example):

  • a.xsd
  • b.xsd
  • c.xsd

c.xsd 特別是導(dǎo)入 b.xsd 和 b.xsd 導(dǎo)入 a.xsd,使用:

c.xsd in particular imports b.xsd and b.xsd imports a.xsd, using:

<xs:include schemaLocation="b.xsd"/>

我正在嘗試通過(guò) Xerces 以下列方式執(zhí)行此操作:

I'm trying to do this via Xerces in the following manner:

XMLSchemaFactory xmlSchemaFactory = new XMLSchemaFactory();
Schema schema = xmlSchemaFactory.newSchema(new StreamSource[] { new StreamSource(this.getClass().getResourceAsStream("a.xsd"), "a.xsd"),
                                                         new StreamSource(this.getClass().getResourceAsStream("b.xsd"), "b.xsd"),
                                                         new StreamSource(this.getClass().getResourceAsStream("c.xsd"), "c.xsd")});     
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new StringReader(xmlContent)));

但這無(wú)法正確導(dǎo)入所有三個(gè)模式,導(dǎo)致無(wú)法將名稱blah"解析為(n)組"組件.

but this is failing to import all three of the schemas correctly resulting in cannot resolve the name 'blah' to a(n) 'group' component.

我已使用 Python 成功驗(yàn)證了這一點(diǎn),但在使用 Java 6.0Xerces 2.8.1 時(shí)遇到了實(shí)際問(wèn)題.誰(shuí)能建議這里出了什么問(wèn)題,或者更簡(jiǎn)單的方法來(lái)驗(yàn)證我的 XML 文檔?

I've validated this successfully using Python, but having real problems with Java 6.0 and Xerces 2.8.1. Can anybody suggest what's going wrong here, or an easier approach to validate my XML documents?

推薦答案

所以以防萬(wàn)一其他人在這里遇到同樣的問(wèn)題,我需要從單元測(cè)試中加載父模式(和隱式子模式) - 作為資源 - 驗(yàn)證 XML 字符串.我使用 Xerces XMLSchemFactory 和 Java 6 驗(yàn)證器來(lái)執(zhí)行此操作.

So just in case anybody else runs into the same issue here, I needed to load a parent schema (and implicit child schemas) from a unit test - as a resource - to validate an XML String. I used the Xerces XMLSchemFactory to do this along with the Java 6 validator.

為了通過(guò)包含正確加載子架構(gòu),我必須編寫一個(gè)自定義資源解析器.代碼可以在這里找到:

In order to load the child schema's correctly via an include I had to write a custom resource resolver. Code can be found here:

https:///code.google.com/p/xmlsanity/source/browse/src/com/arc90/xmlsanity/validation/ResourceResolver.java

要使用解析器,請(qǐng)?jiān)诩軜?gòu)工廠中指定它:

To use the resolver specify it on the schema factory:

xmlSchemaFactory.setResourceResolver(new ResourceResolver());

它將使用它通過(guò)類路徑解析您的資源(在我的例子中來(lái)自 src/main/resources).歡迎對(duì)此提出任何意見...

and it will use it to resolve your resources via the classpath (in my case from src/main/resources). Any comments are welcome on this...

這篇關(guān)于針對(duì)多個(gè)模式定義驗(yàn)證 XML 文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩视频一级 | 成人在线观看欧美 | 精品久久久久久久久久 | 亚洲欧美日韩精品久久亚洲区 | 亚洲精品福利视频 | 国精产品一区一区三区免费完 | 久在线视频播放免费视频 | 黑人中文字幕一区二区三区 | 色综合中文 | 国产欧美精品 | 亚洲视频中文字幕 | 久久网日本 | 欧美日韩视频在线第一区 | 国产精品久久久久一区二区三区 | 日本成人一区二区 | www.中文字幕.com| 久久激情网 | 91在线一区 | 欧美在线视频一区二区 | 亚洲精品一区中文字幕乱码 | 中文字幕在线观看一区二区 | 成人中文网 | 不用播放器看的av | 亚洲成av人影片在线观看 | 亚洲一区二区av | 精品国产一区二区三区久久 | 亚洲精品第一 | 日韩色在线 | 欧美另类视频在线 | 欧美综合一区 | 久久国产精品精品国产色婷婷 | 久久网日本 | 亚洲激情在线观看 | 日韩免费毛片视频 | 搞黄网站在线观看 | 91美女在线 | 亚洲综合免费 | 中文字幕日韩欧美 | 亚洲国产精品久久久 | 精品国产乱码久久久久久闺蜜 | 国产精品一区久久久 |