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

使用導入和包含在 Java 中解析模式?

Parsing Schema in Java With imports and includes?(使用導入和包含在 Java 中解析模式?)
本文介紹了使用導入和包含在 Java 中解析模式?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試將一個相當復雜的 XML 模式解析加載到 Java 中的 Schema 對象中,這樣我就可以對 XML 消息進行一些驗證.

I'm attempting to parse load a rather complicated XML schema into a Schema object in Java so I can do some validation on XML messages.

我的代碼如下所示:

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new StreamSource(new File("schema/schema.xsd")));

我的架構有很多導入:

<?xml version="1.0" encoding="UTF-8"?>
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="base_1">
  <xs:import namespace="base_1" schemaLocation="common/MessageBase.xsd"/>
</xs:schema>

...等等.當我嘗試加載架構時,出現很多錯誤.基于與此相關的另一個問題,我似乎需要指定一個資源解析器,但這不是應該默認處理的事情嗎?

...etc. When I attempt to load the schema, I get lots of errors. Based on one other question related to this, it looks like I need to specify a resource resolver, but isn't this something that should be handled by default?

如果是這樣,我是否需要將架構放置在相對于我正在編寫的應用程序運行位置或相對于基本架構文件的特定目錄中?

If so, is there a specific directory I need to put the schema in relative to where I run the application I'm writing or relative to the base schema file?

最后,當我使用 XMLSpy 或類似工具加載架構時,它工作正常,我可以毫無問題地驗證 XML 實例.

Finally, when I load the schema with XMLSpy or similar, it works fine and I can validate XML instances with no problem.

推薦答案

我認為使用StreamSource,沒有指定基址,是你問題的根源.

I think that the use of StreamSource, without specifying the base location, is the source of your problem.

解析器無法知道主架構在哪里,因此無法解析 common/MessageBase.xml.

The parser has no way of knowing where the main schema is, so it can't resolve common/MessageBase.xml.

使用兩個參數的構造函數并傳入一個 SystemID,它是您開始的路徑名.

Use the two-argument constructor and pass in a SystemID that is the pathname where you're starting from.

查看 StreamSource 的 javadoc.

See the javadoc for StreamSource.

這篇關于使用導入和包含在 Java 中解析模式?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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久久久久久再现 | 青青草一区二区 | www.午夜| 亚洲一区二区三区欧美 | 欧美 日韩 亚洲91麻豆精品 | 成人精品一区二区三区 | 日韩在线播放中文字幕 | 成人精品一区二区户外勾搭野战 | 国产三级一区二区三区 | 亚洲免费在线 | 精品久久久久久久 | 在线欧美视频 | 久久综合香蕉 | 亚洲一区二区三区 | 一区二区三区成人 | 欧美一区二区三区久久精品视 | 一区二区免费 | 男女羞羞在线观看 | 欧美精品国产精品 | 国产一区亚洲二区三区 | 国产成年人小视频 | 盗摄精品av一区二区三区 | 国产一区二区在线免费观看 | 欧美激情在线精品一区二区三区 | 欧美一级毛片在线播放 | 综合色久| 日韩精品在线网站 | 色眯眯视频在线观看 | www.成人免费视频 | 国产激情三区 | 欧美一二精品 | aaa精品| 日本精品一区二区三区视频 | 99re在线视频| 逼逼网 | 综合欧美亚洲 | 精品久久久久国产 | 国产亚洲一区二区在线观看 | 亚洲激情视频在线 |