1

So I am trying to validate an XML file with a schema provided by the XML creator.

DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newDefaultInstance();
dbFactory.setNamespaceAware(true);

DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
StreamSource[] resources = new StreamSource[3];
resources[0] = new StreamSource(new FileInputStream("data/TSL_schema.xsd"));
resources[1] = new StreamSource(new FileInputStream("data/xml.xsd"));
resources[2] = new StreamSource(new FileInputStream("data/xmldsig-core-schema.xsd"));

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(resources);
schema.newValidator().validate(new StreamSource(file));

dbFactory.setSchema(schema);
this.document = dBuilder.parse(file);

The first resource file, namely TSL_schema.xsd contains the following import statements.

<xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>
<xsd:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>

I read in an other StackOverflow post, that W3C is trying to limit the traffic to these webpages, and I assume because of this the code example above takes ~40 sec. to execute. The required imports are respectively resources[1] and resources[2]. My question is whether there is a way to ignore such import statements, and load the files locally.

emilanov
  • 362
  • 4
  • 15

0 Answers0