Org.xml.sax.SAXException: FatalError: [-1,-1] Premature end of file

Boa tarde,

Estou obtendo o erro que está abaixo ao tentar fazer a validação de um XML contra um XSD (Schema).

Exception in thread "main" org.xml.sax.SAXException: FatalError: [-1,-1] Premature end of file.

	at com.neogrid.integrator.xml.XMLSchemaValidator.fatalError(XMLSchemaValidator.java:180)
	at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentScannerImpl$XMLDeclDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
	at org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
	at org.apache.xerces.impl.xs.opti.SchemaDOMParser.parse(Unknown Source)
	at org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
	at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
	at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
	at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
	at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
	at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at pacote.XMLSchemaValidator.validate(XMLSchemaValidator.java:135)
	at pacote.XMLSchemaValidator.main(XMLSchemaValidator.java:190)

Fatos estranhos:

  • Utilizei a ferramenta XMLSpy para verificar se o XML estava realmente bem formatado, e obtive o resultado positivo, meu XML estava bem formatado.
  • Achei então que na hora de carregar o XML ou o XSD meu programa poderia estar “se perdendo” e não carregando os dados, então escrevi no meu console meu XML, e novamente testei no XMLSpy, e a resposta novamente foi, “Valid XML”, ou seja, XML válido!

Alguém teria alguma sugestão do que pode ser?

Ats,
Endrigo Antonini

Para quem está tendo este problema.

O que descobri é que o XML Spy estava gravando a mensagem com caracteres estranhos (Encoding de ISO, se eu não me engano).
Então abri a mensagem com o Editor do Command e removi estes 3 ou quatro caracteres no início da mensagem.
Depois disso não deu mais problema.

Até onde lembro é isso.

Ats,
Endrigo Antonini