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

針對多個模式定義驗證 XML 文件

Validate an XML File Against Multiple Schema Definitions(針對多個模式定義驗證 XML 文件)
本文介紹了針對多個模式定義驗證 XML 文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試針對許多不同的模式驗證 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 特別是導入 b.xsd 和 b.xsd 導入 a.xsd,使用:

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

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

我正在嘗試通過 Xerces 以下列方式執行此操作:

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)));

但這無法正確導入所有三個模式,導致無法將名稱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 成功驗證了這一點,但在使用 Java 6.0Xerces 2.8.1 時遇到了實際問題.誰能建議這里出了什么問題,或者更簡單的方法來驗證我的 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?

推薦答案

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

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.

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

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

要使用解析器,請在架構工廠中指定它:

To use the resolver specify it on the schema factory:

xmlSchemaFactory.setResourceResolver(new ResourceResolver());

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

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...

這篇關于針對多個模式定義驗證 XML 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩一级电影免费观看 | 亚洲国产一区二区三区四区 | 亚洲国产欧美一区二区三区久久 | 91视视频在线观看入口直接观看 | 欧美一区二区在线视频 | 亚洲 欧美 日韩 在线 | 国产精品国产三级国产aⅴ入口 | 欧洲av一区 | 欧美高清hd| 久久成人精品视频 | 久久aⅴ乱码一区二区三区 亚洲欧美综合精品另类天天更新 | 九九热精品视频 | 天天干b | 黄网站在线播放 | 成人aaa视频 | 日韩网站在线观看 | 欧美性猛交一区二区三区精品 | 国产精品一区二区三 | 亚洲精品一区二区在线观看 | 欧美色综合一区二区三区 | 无吗视频| 国产一区二区三区在线 | 福利影院在线看 | 中文字幕免费视频 | 免费观看成人鲁鲁鲁鲁鲁视频 | 超碰网址 | 成人在线国产 | 91中文字幕在线观看 | 成人激情视频免费观看 | 中文字幕视频在线 | 日韩欧美在线一区 | 欧美不卡一区二区三区 | 麻豆亚洲| 久久精品国产免费高清 | 99久热| 另类亚洲视频 | 一区二区三区av | 中文在线а√在线8 | www.久 | 在线一区视频 | 欧美一级淫片免费视频黄 |