2014-07-22 64 views
0

背景:Java實現不需要通過SchemaFactory實現RELAX NG驗證?

我有一個RELAX NG模式,並且都應該遵循此模式的幾個XML文件。我想在XML文件驗證Java中的架構,我得到一個錯誤:

No SchemaFactory that implements the schema language specified by: http://relaxng.org/ns/structure/1.0 could be loaded

我發現this post同樣的問題和答案的人說,

Java implementations are not required to implement RELAX NG validation via SchemaFactory. So even if it works in one environment, it is not portable...

問:

這是真的,我不能創建一個便攜式驗證器,而不依賴於之類的東西the Jing library RELAX NG?

我試圖避免在我的應用程序中使用外部庫。

驗證在Java中:

 ... 

     DocumentBuilderFactory builder = DocumentBuilderFactory.newInstance(); 
     builder.setNamespaceAware(true); 
     SchemaFactory schfactory = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI); 

     Schema schema = schfactory.newSchema(new File("Configuration/Schema.rng")); 
     builder.setSchema(schema); 
     Validator validator = schema.newValidator(); 


     DocumentBuilder build = builder.newDocumentBuilder(); 
     Document doc = build.parse(new File(filepath)); 
     DOMSource source = new DOMSource(doc); 

     validator.validate(source); 

     ... 

回答

0

是的,這是事實。就我所知,W3C定義的XML Schema是唯一的可移植模式語言。 RELAX NG引入了正常XML模式之外的其他功能。

0

這個IBM Post澄清了我的問題。

Out of the box, the JDK doesn't include a RELAX NG validator.