Validar XML da NFe

Bem pessoal estou tentando validar o XML de uma NFe, mas está me mostrando o erro

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
			docBuilderFactory.setNamespaceAware(true);
			docBuilderFactory.setValidating(true);
			docBuilderFactory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
			
			String []schemas = {"c:\\SIAM\\schema\\leiauteNFe_v2.00.xsd", "c:\\SIAM\\schema\\tiposBasico_v1.03.xsd"};
			docBuilderFactory.setAttribute(JAXP_SCHEMA_SOURCE, schemas);
			
			DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
			Document document = builder.parse("c:\\SIAM\\XML\\nota.xml");
java.lang.IllegalArgumentException:  When using array of Objects as the value of SCHEMA_SOURCE property , no two Schemas should share the same targetNamespace. 
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
	at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

alguem ja teve esse problema?

Faça assim:

[code]package servico.cce.usefull;

import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
*

  • @author Dilnei Cunha.
    */
    public class Valida {

    /**

    • Método que faz a validação de arquivos XML.

    • @param fullFileName

    • @param xsdFullFileName

    • @return

    • @throws Throwable
      */
      public static boolean validate(String fullFileName, String xsdFullFileName) throws Throwable {

      // Crio a fabrica.
      DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

      // Habilito suporte a namespace.
      documentBuilderFactory.setNamespaceAware(true);
      documentBuilderFactory.setValidating(true);

      // Atributos para validação.
      documentBuilderFactory.setAttribute(“http://java.sun.com/xml/jaxp/properties/schemaLanguage”, “http://www.w3.org/2001/XMLSchema”);
      documentBuilderFactory.setAttribute(“http://java.sun.com/xml/jaxp/properties/schemaSource”, xsdFullFileName);

      // Crio uma builder para obter o Document de um .xml
      DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

      // Guardo os erros de validação.
      ErrorHandler errorHandler = new ErrorHandler();
      documentBuilder.setErrorHandler(errorHandler);

      // Declaro as variaveis a serem utilizadas.
      Document document = null;

      try {
      // Primeiro parse.
      document = documentBuilder.parse(fullFileName);
      } catch (SAXException e) {
      e.getMessage();
      }

      SchemaFactory schemaFactory = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);

      // carrega um WXS schema, representada por uma instacia Schema.
      Source schemaFile = new StreamSource(new File(xsdFullFileName));
      Schema schema = schemaFactory.newSchema(schemaFile);

      // Cria um objeto ValidationHandler que pode ser usado para validar uma instancia document.
      Validator validator = schema.newValidator();

      // Indica o objeto que irá tratar os error. Observe que ao encontrar
      // um erro, este é simplesmente guardado e processo de validação continua.
      try {
      // Efetua a validação propriamente.
      validator.validate(new DOMSource(document));
      } catch (Exception e) {
      // Se algum erro foi encontrado, apresenta-o.
      if (!errorHandler.handlerList.isEmpty()) {
      for (String error : errorHandler.handlerList) {
      System.out.println(error);
      }
      }
      return false;
      }
      return true;
      }
      }
      [/code]

handler:

package servico.cce.usefull;

import java.util.ArrayList;
import java.util.List;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/**
 *
 * @author Dilnei Cunha
 */
public class ErrorHandler implements org.xml.sax.ErrorHandler {
    
    final List<String> handlerList= new ArrayList<String>();
    
    @Override
    public void warning(SAXParseException exception) throws SAXException {
        handlerList.add("ATENÇÃO: " + exception.getMessage());
    }

    @Override
    public void error(SAXParseException exception) throws SAXException {
        handlerList.add("ERRO: " + exception.getMessage());
    }

    @Override
    public void fatalError(SAXParseException exception) throws SAXException {
        handlerList.add("ERRO FATAL: " + exception.getMessage());
    }
}

Bem cara fiz isso ai, mas o que está aparecendo agora é:

ATENÇÃO: schema_reference.4: Failed to read schema document ‘xmldsig-core-schema_v1.01.xsd’, because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not xsd:schema.

ATENÇÃO: schema_reference.4: Failed to read schema document ‘tiposBasico_v1.03.xsd’, because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not xsd:schema.

Pelo o que entendi, não está carregando esses esquemas, sabe como resolver isso?

pelo erro ele não esta encontrando teus .xsd, verifique com debug se ele esta indo no local certo onde estão seus arquivos .xsd

Ow campeão vlw, era burrada minha
no meu XSD não estava apontando para o diretorio certo rs

vlw agora funcionou