Hi Fabio, Likely your instance document is invalid, but you haven't posted it or the definition of the complex type "TNFe" so I can't really tell.
P.S. When you reply please keep the mailing list CC'd. You benefit by having more people hear your problem (who may experienced something similar and can help you troubleshoot it) and they might benefit from hearing the solution when you resolve it. Thanks. Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] "Fabio Retzlaff" <[EMAIL PROTECTED]> wrote on 04/11/2007 08:41:41 AM: > Hi Michael, > > I changed my code as below, but now I get this error: > Error: URI=null Line=314: cvc-complex-type.2.4.b: The content of element > 'NFe' is not complete. One of > '{"http://www.w3.org/2000/09/xmldsig#":Signature}' is expected. > > > public static void validate2(String[] schemas) > throws Exception { > > > System.setProperty("javax.xml.parsers.DocumentBuilderFactory", > > "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); > > DocumentBuilderFactory factory = > DocumentBuilderFactory.newInstance(); > factory.setNamespaceAware(true); > factory.setValidating(true); > factory.setXIncludeAware(true); > > InputStream is = ClassLoader > > .getSystemResourceAsStream("message.xml"); > > factory.setAttribute( > > "http://java.sun.com/xml/jaxp/properties/schemaLanguage", > "http://www.w3.org/2001/XMLSchema"); > factory.setAttribute( > > "http://java.sun.com/xml/jaxp/properties/schemaSource", > schemas); > > DocumentBuilder builder = factory.newDocumentBuilder(); > builder.parse(is); > > } > > Here is my schema: > > <?xml version="1.0" encoding="UTF-8"?> > <xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns="http://www.portalfiscal.inf.br/nfe" > targetNamespace="http://www.portalfiscal.inf.br/nfe" > elementFormDefault="qualified" attributeFormDefault="unqualified"> > <xs:include schemaLocation="leiauteNFe_v1.08.xsd"/> > <xs:element name="NFe" type="TNFe"/> > </xs:schema> > > > leiauteNFe_v1.08.xsd: > <?xml version="1.0" encoding="UTF-8"?> > <xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns="http://www.portalfiscal.inf.br/nfe" > targetNamespace="http://www.portalfiscal.inf.br/nfe" > elementFormDefault="qualified" attributeFormDefault="unqualified"> > <xs:import namespace="http://www.w3.org/2000/09/xmldsig#" > schemaLocation="xmldsig-core-schema_v1.01.xsd"/> > <xs:include schemaLocation="tiposBasico_v1.00.xsd"/> > <xs:complexType name="TNFe"> > ... > > tiposBasico_v1.00.xsd: > <?xml version="1.0" encoding="UTF-8"?> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:nfe="http://www.portalfiscal.inf.br/nfe" > targetNamespace="http://www.portalfiscal.inf.br/nfe" > elementFormDefault="qualified" attributeFormDefault="unqualified"> > <xs:simpleType name="TCodUfIBGE"> > ... > > > > -----Mensagem original----- > De: Michael Glavassevich [mailto:[EMAIL PROTECTED] > Enviada em: quarta-feira, 11 de abril de 2007 02:14 > Para: j-users@xerces.apache.org > Assunto: Re: Problem with included XSD > > Hi Fabio, > > You aren't setting namespace awareness to true on the > DocumentBuilderFactory. Both schema validation and XInclude require > namespace support. Assuming your schema actually contains an element > declaration for "NFe", I imagine setting namespace awareness would make > it > work. > > Note that you're not actually using Apache Xerces. > com.sun.org.apache.xerces.* classes are part of Sun's three year old > fork > off the Xerces codebase. It has bugs which are unique to it and others > which have long been fixed in Apache so you may run into problems which > users here have never experienced (and never will experience). > > Thanks. > > Michael Glavassevich > XML Parser Development > IBM Toronto Lab > E-mail: [EMAIL PROTECTED] > E-mail: [EMAIL PROTECTED] > > "Fabio Retzlaff" <[EMAIL PROTECTED]> wrote on 04/10/2007 > 03:46:23 PM: > > > Hi, > > > > I'm trying to validate a xml using a schema with include but I get > this > > error: > > > > org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration > of > > element 'NFe'. > > at > > > com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseExcept > > ion(Unknown Source) > > at > > > com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.e > > rror(Unknown Source) > > > > Here is my code: > > > > public Document validate (String message, String[] schemas) > > throws Exception { > > > > > System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org > > /2001/XMLSchema", > > > "com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaFactoryImpl > > "); > > > > > System.setProperty("org.w3c.dom.DOMImplementationSourceList","com.sun.or > > g.apache.xerces.internal.dom.DOMXSImplementationSourceImpl"); > > //try { > > > > DOMParser dp = new DOMParser(); > > > > > dp.setFeature("http://apache.org/xml/features/nonvalidating/load-externa > > l-dtd",false); > > > > dp.setFeature("http://xml.org/sax/features/validation",false); > > > > > dp.setFeature("http://apache.org/xml/features/validation/schema",false); > > dp.parse(new InputSource(new StringReader(message))); > > Document doc = dp.getDocument(); > > Element de = doc.getDocumentElement(); > > NamedNodeMap nnm = de.getAttributes(); > > > > Attr att1 = doc.createAttribute("xmlns:xsi"); > > > > att1.setValue("http://www.w3.org/2001/XMLSchema-instance"); > > nnm.setNamedItem(att1); > > > > Node n = > > nnm.getNamedItem("xsi:noNamespaceSchemaLocation"); > > if (n !=null) nnm.removeNamedItemNS(n.getNamespaceURI(), > > n.getLocalName()); > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > > XMLSerializer ser = new XMLSerializer(baos,new > > OutputFormat()); > > ser.serialize(doc); > > baos.close(); > > > > message = new String(baos.toByteArray()); > > > > DocumentBuilderFactory docFactory = > > DocumentBuilderFactory.newInstance(); > > docFactory.setXIncludeAware(true); > > DocumentBuilder parser = docFactory.newDocumentBuilder(); > > Document document = parser.parse(new InputSource(new > > StringReader(message))); > > > > SchemaFactory factory = > > SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); > > Source[] sources = new Source[schemas.length]; > > for (int i = 0; i < sources.length; i++) { > > StreamSource s = new StreamSource(new > > ClassPathResource(schemas[i]).getInputStream()); > > sources[i] = s; > > } > > Schema schema = factory.newSchema(sources); > > Validator validator = schema.newValidator(); > > validator.validate(new DOMSource(document)); > > return document; > > } > > > > There is anything wrong ?? > > > > Fabio > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]