SourceForge has been redesigned. Learn more.
Close

schemaLocation cause unvalid XML

Help
2009-05-13
2013-03-03
  • bloodflowers

    bloodflowers - 2009-05-13

    Hi
    I have a big problem with a validation of a xml with schemas on java.

    I have this validation method:

    public boolean validate(File xmlDocument, File xmlSchemaFile) throws SecurityException, FileNotFoundException, ConfigurationException, SAXException{
            InputSource is = new InputSource(new FileInputStream(xmlDocument));
            Validator v = new Validator(is);
            v.useXMLSchema(true);
            v.setJAXP12SchemaSource(xmlSchemaFile);
            System.out.println(v.toString());
            return v.isValid();
        }

    first schema:

    devices.xsd

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        elementFormDefault="qualified" targetNamespace="http://devices.xsd"
        xmlns:a="http://zbport.xsd" xmlns:j="http://devices.xsd">
       
        <xs:import namespace="http://zbport.xsd"
            schemaLocation="zbport.xsd" />

          <xs:element name="j" type="xs:NMTOKEN"/>
    ...
    </xs:schema>

    second schema:

    zbport.xsd

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        elementFormDefault="qualified" targetNamespace="http://zbport.xsd"
        xmlns:a="http://zbport.xsd" xmlns:j="http://devices.xsd">
       
        <xs:import namespace="http://zbport.xsd"
            schemaLocation="devices.xsd" />
        
                   <xs:element name="v">
                     <xs:complexType>
                        <xs:sequence>
                           <xs:element maxOccurs="unbounded" ref="j:j"/>
                       </xs:sequence>
                      <xs:attribute name="version" use="required" type="xs:NMTOKEN"/>
                     </xs:complexType>
                 </xs:element>
    ...
    </xs:schema>

    the XML file is:

    myxml.xml

    <a:v version="1.1.0" xmlns:a="http://zbport.xsd"
        xmlns:j="http://devices.xsd">
        <j:j>aaa</j:j>
    </a:v>

    All files are in the same folder. ( C:/workspace/valitator/)

    If I turn the validator I receive the error:
    org.custommonkey.xmlunit.Validator@e39a3e:schema_reference.4: Failed to read schema document 'file:///C:/devices.xsd'

    Thanks for help

     
    • Stefan Bodewig

      Stefan Bodewig - 2009-05-28

      The first thing I'd try is using the "new" jaxp13.Validator for schema validation, this may or may not work better.  In any case it will give you a list of SAXParseExceptions with full location information which may be helpful.

      I'm not convinced that any schemaLocation attribute is causing the problem, why do you think it is?

      Does validation work if you specify both schema documents as schema sources at the same time?

      Stefan

       

Log in to post a comment.