久久久久久久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中文字幕在线播放 | 国产成人麻豆免费观看 | 国产视频一区在线 | 一级无毛片 | 国产精品1区 | 国产精品99久久久精品免费观看 | 91精品国产91久久久久游泳池 | 特级黄一级播放 | 国产精品成人品 | 久久精品亚洲精品 | 亚洲不卡在线观看 | 久久精品一区二区三区四区 |