Warning: validation was turned on but an org.xml.sax.ErrorHandler

前端 未结 3 1476
执念已碎
执念已碎 2021-01-07 02:40

Any idea why this error is happening and how to fix it? I\'m getting this error when trying to parse/load a config file:

Error

Warning: validation wa         


        
相关标签:
3条回答
  • 2021-01-07 03:11

    The exception says that an ErrorHandler wasn't set. This means that the parser uses its built-in error handler, which simply writes messages to the console. If you actually want to validate, you need to create an ErrorHandler implementation and attach it to the DocumentBuilder.

    For more information, read this: http://www.kdgregory.com/index.php?page=xml.parsing (error handlers are about 1/3 of the way down).

    Or, as other responses have suggested, you can just turn validation off.

    0 讨论(0)
  • 2021-01-07 03:12

    If your parsing an XML document with validation turned on, you need to specify either a DTD or an XML schema in a DOCTYPE at the start of your XML document. Your parser is basically complaining that it doesn't know how to validate your document because no grammer has been specified to validate the mark up.

    You already have an XML schema, so you probably want:

    <!DOCTYPE schema PUBLIC "http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    

    If you want to turn off validation, you need something like:

    spf.setValidating(false); (Where spf is a SaxParserFactory)

    0 讨论(0)
  • 2021-01-07 03:20

    The XML document defines the default namespace http://java.sun.com/xml/ns/persistence and includes a url, where the schema can be found (xsi:schemaLocation attribute, first value is the namespace, second the url or path).

    Please double-check if this url is accessible at the time you parse it. An alternative is to download the schema, put it on the file system and modify the xsi:schemaLocation value.

    0 讨论(0)
提交回复
热议问题