[英]JAVA: How to use the xerces SAXParser using multiple schemas with identical targetNamespaces
我需要使用一組模式對傳入的XML片段執行一些驗證。
所有這些架構共享相同的targetNamespace,但分為不同的.xsd文件。
我的Java程序正在將每個xsd文件加載到InputSource []數組中,並將它們傳遞到SAX Parser(SCHEMA_SOURCE屬性)中。 但是,當調用XMLReader.parse方法時,我得到以下堆棧跟蹤:
** java.lang.IllegalArgumentException:當使用Objects數組作為SCHEMA_SOURCE屬性的值時,任何兩個模式都不應共享相同的targetNamespace。 在org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(未知源)在org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(未知源)在org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar (未知來源)在org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(未知來源)在org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(未知來源)在org.apache.xerces.impl.xs.XMLs org.apache.xerces.impl.XMLNSDocumentScannerImpl $ NSContentDispatcher.scanRootElementHook(未知源)org.apache.xerces.impl.XMLDocumentFragmentScannerImpl $ FragmentContentDispatcher.dispatch(未知源)org.apache.xerces.ier org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)上的.XMLDocumentFragmentScannerImpl.scanDocument(org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)上的org.apache.xerces.parsers.XMLParser .parse(未知來源),位於org.apache.x erces.parsers.AbstractSAXParser.parse(未知來源)**
我需要使用共享名稱空間的架構來解析XML。 是否可以這樣做並避免上述錯誤?
任何形式的幫助或建議,將不勝感激
謝謝
不,這是不可能的。 它由XML和架構規范強制執行。
實體或屬性只能與一個名稱空間相關聯,該名稱空間可以是默認的隱式名稱空間,也可以是顯式的名稱空間作為前綴。
一條建議:如果您的XML輸入格式正確,但由於未聲明名稱空間而無法驗證,但您有一個想法,如何實現一種邏輯,該邏輯可以根據每個節點的上下文(例如其先前節點或它的節點)來猜測名稱空間是什么父節點。 您可以創建一個預處理器:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.