SXXP0003:XML解析器报告错误:schematron xml中的prolog中不允许使用内容

时间:2016-12-27 09:19:25

标签: java xml schematron

我正在尝试运行probatron4j。这是源项目

https://code.google.com/archive/p/probatron4j/downloads

我使用ant构建这个项目,我在dist文件夹中获得了probatron.jar。

但是当我尝试根据Schematron架构验证我的XML时,显示

C:\Users\sukumar\Downloads\probatron4j-source-0.7.4>java -jar dist\probatron.jar xml\sample.xml sch\sample.sch          Error on line 4 column 16
SXXP0003: Error reported by XML parser: Content is not allowed in prolog.                                             
FATAL org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 16; Content is not allowed in prolog.                 
Exception in thread "main" java.lang.RuntimeException: Cannot instantiate XSLT transformer, 
or transformation failure: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 16; Content is not allowed in prolog. 

at org.probatron.SchematronSchema.validateCandidate(Unknown Source)                                                     at org.probatron.SchematronSchema.validateCandidate(Unknown Source)  

at org.probatron.Session.doValidation(Unknown Source)                                                                   
   at org.probatron.Driver.main(Unknown Source)                                                                    
Caused by: net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 16; Content is not allowed in prolog.                                                                                                         
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:418)                                                             at net.sf.saxon.event.Sender.send(Sender.java:214)                                                                      
at net.sf.saxon.event.Sender.send(Sender.java:50)                                                                       at net.sf.saxon.Controller.transform(Controller.java:1611)                                                              
... 4 more                                                                                                      
Caused by: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 16; Content is not allowed in prolog.                   
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)                                                                                                                            
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)                
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)                   
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)                     
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)                            
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:999)                                                                                                                            
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)                
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)             
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)                                                                                                                 
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)                    
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)                   
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)                                       
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)                    
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)               
 at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:404)                                                             ... 7 more  

这是schematron xml

<?xml version="1.0" encoding="utf-8"?>
<schema xmlns="http://www.ascc.net/xml/schematron" > 
         <pattern name="Print negative result only"> 
          <rule context="AAA"> 
               <assert test="BBB">BBB element is missing.</assert> 
               <assert test="@name">AAA misses attribute name.</assert> 
          </rule> 
     </pattern> 
</schema>

和需要测试的xml

<AAA>
    <BBB/>
</AAA>

我用来运行jar文件的命令

C:\Users\sukumar\Downloads\probatron4j-source-0.7.4>java -jar dist\probatron.jar xml\sample.xml sch\sample.sch  

1 个答案:

答案 0 :(得分:0)

Schematron命名空间存在问题。我更改了名称空间

xmlns="http://www.ascc.net/xml/schematron"

到这个

xmlns="http://purl.oclc.org/dsdl/schematron"
            xmlns:sch="http://purl.oclc.org/dsdl/schematron"
            xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
            xmlns:ef="http://www.efatura.gov.tr/envelope-namespace"

这对我有用。