1

I am pretty new to xsds, and currently the xsd I am using is only validating on some machines. It works on my local machine, but when I try doing this on a machine where there are some proxies or firewalls, it no longer works. The schemas I am using are used locally, though.

Here is the error I get when the xsd schema is attempting to validate:

src-resolve: Cannot resolve the name 'xenc:EncryptedDataType' to a(n) 'type definition' component.

Which comes from this code:

boolean validate(URL schemaUrl) {
        SchemaFactory schemaFactory = SchemaFactory
                .newInstance("http://www.w3.org/2001/XMLSchema");
        Schema schema = null;
        try {
            schema = schemaFactory.newSchema(schemaUrl); //this is where the exception is thrown
        } catch (SAXException e) {
            //exception is caught here
            return false;
        }
        //... more code here
}

The error has the same stack trace as this one: SAXParseException; src-resolve: Cannot resolve the name '...' to a(n) 'type definition' component

I have my main xsd that begins something like this:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
           xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
           xmlns:tns="http://customization.elster.com/shipment"
           targetNamespace="http://customization.client.com/introduction"
           attributeFormDefault="unqualified"
           elementFormDefault="qualified"
           version="1.1" >
    <xs:import namespace="http://www.w3.org/2001/04/xmlenc#" schemaLocation="xenc-schema.xsd"/>
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>

in this main XML I need the "xenc:EncryptedDataType"

<xs:complexType name="NamedEncryptedDataType">
        <xs:complexContent>
            <xs:extension base="xenc:EncryptedDataType">
                <xs:attribute name="name" type="xs:string" use="required"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

which is defined in the xenc-schema.xsd (which is in the same folder as my main xsd)

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE schema  PUBLIC "-//W3C//DTD XMLSchema 200102//EN"
 "http://www.w3.org/2001/XMLSchema.dtd"
 [
<!ATTLIST schema
     xmlns:xenc CDATA #FIXED 'http://www.w3.org/2001/04/xmlenc#'
     xmlns:ds CDATA #FIXED 'http://www.w3.org/2000/09/xmldsig#'>
   <!ENTITY xenc 'http://www.w3.org/2001/04/xmlenc#'>
   <!ENTITY % p ''>
   <!ENTITY % s ''>
  ]>

<schema xmlns='http://www.w3.org/2001/XMLSchema' version='1.0'
        xmlns:xenc='http://www.w3.org/2001/04/xmlenc#'
        xmlns:ds='http://www.w3.org/2000/09/xmldsig#'
        targetNamespace='http://www.w3.org/2001/04/xmlenc#'
        elementFormDefault='qualified'>

  <import namespace='http://www.w3.org/2000/09/xmldsig#'
          schemaLocation='xmldsig-core-schema.xsd'/>

in this xenc-schema, there is the culprit data type:

  <element name='EncryptedData' type='xenc:EncryptedDataType'/>
  <complexType name='EncryptedDataType'>
    <complexContent>
      <extension base='xenc:EncryptedType'>
       </extension>
    </complexContent>
  </complexType>

I've tried to keep this question shorter, let me know if more information is needed, thanks for reading.

Community
  • 1
  • 1
Vlad Ilie
  • 1,389
  • 1
  • 13
  • 37

1 Answers1

1

The best way to diagnose these sort of problems is to install an HTTP debugger. For e.g., Fiddler is a good one that should work for you. It should tell you what resource is resolved externally (on the Internet).

In your case, most likely the culprit is the DTD in your xenc-schema.xsd file. To quickly prove it, simply get rid of any embedded DTDs. Once you prove the issue, you may choose to simply keep the edited XSDs, or use a custom EntityResolver, or see if your particular library has some sort of property you can set to disable DTD processing (which is really useless here).

Petru Gardea
  • 21,373
  • 2
  • 50
  • 62
  • Seems that removing the doctype entirely, with the DTD did the trick. Thank you for the suggestion. – Vlad Ilie Aug 02 '16 at 09:52
  • @VladIlie, I think I saw an earlier comment re: not seeing any external traffic. Just to make sure, for Java apps you need to configure your proxy information - this [link](http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/ConfigureJavaApp) might prove helpful. – Petru Gardea Aug 02 '16 at 14:20