久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产成人小视频 | 国产高清在线精品一区二区三区 | 国产一区二区三区四区区 | 少妇久久久 | 青青久久 | 成人精品一区二区三区 | 欧美黄色一区 | 羞羞网站在线观看 | 中文字幕综合 | 国产精品美女久久久 | 日韩精品一区二区在线 | 欧美成人在线网站 | 亚洲色图综合 | 亚洲成人自拍 | 色爱综合网 | 国产成人在线一区二区 | 国产精品久久久久久久久图文区 | 粉嫩国产精品一区二区在线观看 | 中文字幕第十页 | 好好的日在线视频 | a级片网站 | 国产一级淫片免费视频 | 欧美成人aaa级毛片在线视频 | 激情毛片| 色婷婷久久综合 | 久久草在线视频 | 精久久久 | 久久久久久免费精品一区二区三区 | 青青草国产在线观看 | 亚洲不卡在线观看 | 黄色大片观看 | 在线观看午夜视频 | 国产高清视频在线观看播放 | 亚洲成人一二区 | 国产日韩欧美激情 | 国产 欧美 日韩 一区 | 久久久国产一区二区三区四区小说 | 午夜在线电影网 | 中文字幕11页 | 亚洲精品一区二三区不卡 | 在线91|