Hi Danny, You have at least one import in your graph of schema documents which points to a resource on the net.
>From xhtml11.xsd: <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"> <xs:annotation> <xs:documentation> This import brings in the XML namespace attributes The XML attributes are used by various modules. </xs:documentation> </xs:annotation> </xs:import> That's one reason why it might take so long. The W3C sometimes blocks requests [1] for its schemas/DTDs or returns things very slowly. Have a look at XML Catalogs [2] and entity resolvers as lighter alternatives to fetching these external resources from the net every time. Thanks. [1] http://www.w3.org/blog/systeam/2008/02/08/w3c_s_excessive_dtd_traffic/ [2] http://xerces.apache.org/xerces2-j/faq-xcatalogs.html Michael Glavassevich XML Technologies and WAS Development IBM Toronto Lab E-mail: mrgla...@ca.ibm.com E-mail: mrgla...@apache.org Danny Sinang <d.sin...@gmail.com> wrote on 03/19/2012 05:16:37 PM: > Hello, > > I'm trying to validate the attached XML document (MBS1172478.xml) > against an XSD file (xplana_2.xsd inside schema.zip) but I can't get > past the line > > Schema schema = factory.newSchema(schemaLocation); > > It takes too long (like 5 to 10 minutes) when I run my code in a > jUnit test, after which I get the following error : > > org.xml.sax.SAXParseException: sch-props-correct.2: A schema cannot > contain two global components with the same name; this schema > contains two occurrences of 'http://www.w3.org/1999/xhtml,Length'. > > My jUnit looks like this : > > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > import java.io.InputStream; > import java.util.ArrayList; > import java.util.Enumeration; > import java.util.HashMap; > import java.util.List; > import java.util.zip.ZipEntry; > import java.util.zip.ZipException; > import java.util.zip.ZipFile; > > import javax.xml.XMLConstants; > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > 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.junit.Test; > import org.junit.runner.RunWith; > import org.simpleframework.xml.Serializer; > import org.simpleframework.xml.convert.AnnotationStrategy; > import org.simpleframework.xml.core.Persister; > import org.simpleframework.xml.strategy.Strategy; > import org.springframework.test.context.ContextConfiguration; > import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; > import org.w3c.dom.Document; > import org.xml.sax.SAXException; > > @RunWith(SpringJUnit4ClassRunner.class) > @ContextConfiguration(locations = { "/xplana-marklogic-test.xml" }) > public class ValidationV2Test { > > private void validateXml (File xmlFile) throws > ParserConfigurationException, SAXException, IOException { > > // parse an XML document into a DOM tree > DocumentBuilderFactory parserFactory = > DocumentBuilderFactory.newInstance(); > parserFactory.setNamespaceAware(true); > DocumentBuilder parser = parserFactory.newDocumentBuilder(); > Document document = parser.parse(xmlFile); > > // create a SchemaFactory capable of understanding WXS schemas > SchemaFactory factory = SchemaFactory.newInstance > (XMLConstants.W3C_XML_SCHEMA_NS_URI); > > // load a WXS schema, represented by a Schema instance > File schemaLocation = new File("D:\\schema\\xplana_2.xsd"); > Schema schema = factory.newSchema(schemaLocation); > > // create a Validator instance, which can be used to validate an > instance document > Validator validator = schema.newValidator(); > > // validate the DOM tree > try { > validator.validate(new DOMSource(document)); > System.out.println("Validation successful."); > } catch (SAXException e) { > // instance document is invalid! > } > > } > > @Test > public void v2PrototypeTest() { > validateXml("D:\\temp\\MBS1172478\\MBS1172478.xml"); > } > > } > > Any idea what I'm doing wrong ? > > I validated the same XML against the same XSD using OxygenXML and > MarkLogic and it validates fine. > > Regards, > Danny > > --------------------------------------------------------------------- > To unsubscribe, e-mail: j-users-unsubscr...@xerces.apache.org > For additional commands, e-mail: j-users-h...@xerces.apache.org