Can't duplicate Oxygen's validation using Xerces-J 2.7.0

This should cover W3C XML Schema, Relax NG and DTD related problems.
samwise
Posts: 9
Joined: Tue Jul 12, 2005 9:42 pm

Can't duplicate Oxygen's validation using Xerces-J 2.7.0

Post by samwise »

Hi,

With some help on another online forum, I have modified the SPML schema so I can validate an SPML message against the schema. To do this, I had to specify a namespace in all the <xsd:any> elements like this

<xsd:any namespace="##local" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>

I also had to relax a regular expression in the DSML standard which the parser didn't appear to like.

Here are the schemas I started with:

http://www.oasis-open.org/committees/do ... ma-1.0.xsd

This imports these two schemas:

http://www.oasis-open.org/committees/ds ... DSMLv2.xsd
http://www.oasis-open.org/committees/se ... ion-01.xsd

The last one imports:

http://www.w3.org/TR/xmldsig-core/xmlds ... schema.xsd

After making the two modifications described above, I can create a .xml file containing an SPML request like this SearchRequest:

<?xml version="1.0" encoding="UTF-8"?>

<spml:searchRequest xmlns:spml='urn:oasis:names:tc:SPML:1:0' xmlns:dsml='urn:oasis:names:tc:DSML:2:0:core' requestID='myId'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:oasis:names:tc:SPML:1:0 os-pstc-spml-schema-1.0.xsd">
<operationalAttributes>
<dsml:attr name='my_param_name'>
<dsml:value>param_name_value1</dsml:value>
</dsml:attr>
<dsml:attr name='my_second_param'>
<dsml:value>value2</dsml:value>
</dsml:attr>
</operationalAttributes>
<searchBase type='urn:oasis:names:tc:SPML:1:0#GenericString'>
<id>my_friend</id>
<identifierAttributes>
<dsml:attr name='idkey'>
<dsml:value>uniquenumber1</dsml:value>
</dsml:attr>
<dsml:attr name='secondidkey'>
<dsml:value>diffuniquenumber2</dsml:value>
</dsml:attr>
</identifierAttributes>
</searchBase>
</spml:searchRequest>

This can be validated in Oxygen, against the four schemas I have stored locally.

What I would like to do now is perform this programmatically in Java using Xerces which I believe Oxygen is based on. I wrote this program:

package org.samwise.code;

import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import org.apache.xerces.parsers.DOMParser;

public class DOMSchemaValidator {

private class Validator extends DefaultHandler
{
public boolean validationError = false;
public SAXParseException saxParseException = null;

public void error(SAXParseException exception) throws SAXException
{
validationError = true;
saxParseException = exception;
}
public void fatalError(SAXParseException exception) throws SAXException
{
validationError = true;
saxParseException = exception;
}
public void warning(SAXParseException exception) throws SAXException
{
}
}

public void validateSchema(String XmlDocumentUrl)
{

try
{

DOMParser domParser = new DOMParser();
System.out.println("created object");

domParser.setFeature("http://xml.org/sax/features/namespaces", true);
domParser.setFeature("http://xml.org/sax/features/validation",true);
domParser.setFeature("http://apache.org/xml/features/validation/schema",true); domParser.setFeature("http://apache.org/xml/features/validati ... king",true);
domParser.setFeature("http://apache.org/xml/features/honour-a ... aLocations", true);

Validator handler = new Validator();
domParser.setErrorHandler(handler);
domParser.parse(XmlDocumentUrl);

if(handler.validationError==true)
{
handler.saxParseException.printStackTrace();
}
else
System.out.println("XML Document is valid");

System.out.println("done the parse");

}
catch (Exception e)
{
e.printStackTrace();
}
}

public static void main (String args[])
{
System.out.println("Validating XML");
String XmlDocumentUrl = "SPMLXMLSchema/testspml.xml";
DOMSchemaValidator validator = new DOMSchemaValidator();
validator.validateSchema(XmlDocumentUrl);
System.exit(0);
}

}

However, using the Xerces-J 2.7.0 binaries, I keep getting this error message:

org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'ds:Signature' to a(n) 'element declaration' component.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseLocal(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.traverseLocalElements(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.samwise.code.DOMSchemaValidator.validateSchema(DOMSchemaValidator.java:75)
at org.samwise.code.DOMSchemaValidator.main(DOMSchemaValidator.java:100)

Which indicates it cannot load the last XML Schema in the chain: xmldsig-core-schema.xsd.

To be clear, I have downloaded all four schemas and stored them locally, dropping the http:// parts of the schemaLocation in the relevant namespace import statements.

Any suggestions? Again, the validation works fine within Oxygen - so I assume I am misusing the DOM parser in my java code above.

Many thanks for any response,

Sam.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Sam,

Please zip all the files (schemas and sample) and send then to support at oxygenxml dot com. At a first glance the schemas and the instance are wrong - but you said you use modified varsions of these schemas so I cannot give a clear answer unless I see the schemas and the instance.

Best Regards,
George
samwise
Posts: 9
Joined: Tue Jul 12, 2005 9:42 pm

RE: Can't duplicate Oxygen's validation using Xerces-J 2.7.0

Post by samwise »

George,

I've just sent the code, the XML schemas and the example message I'm trying to validate to the support email address.

The XML Schemas I linked to do contain some problems which stop them from validating, which is what I referred to when I detailed the modifications I made. Basically, the DSML XML Schema contains a regular expression which the parser does not appear to like - I have simply relaxed this expression at the moment. The other parsing errors relate to the SPML schema, which I overcame by specifying a namespace in the <any> tags.

Anyway, hopefully looking at the files will help show what I'm trying to do.

Feel free to come back if I can clarify anything!

Thanks for the interest,

Sam.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Sam,

Thanks for sending the files.
I tried your sample with a small change

String XmlDocumentUrl = "file:/F:/test2/sam/SPMLXMLSchema/testspml.xml";

and that works ok with Xerces 2.7.2. It may be a problem related with the location of the file as you had a relative location:

String XmlDocumentUrl ="SPMLXMLSchema/testspml.xml";

If the path contains spaces or some other special characters that may make the parser fail to locate the schema.

Try also with specifying the full location of the XML file.

Best Regards,
George
samwise
Posts: 9
Joined: Tue Jul 12, 2005 9:42 pm

RE: Can't duplicate Oxygen's validation using Xerces-J 2.7.0

Post by samwise »

Hi, George,

I moved all the XML files to a directory off \ and re-ran the code with:

String XmlDocumentUrl = "file:/C:/SPMLXMLSchema/testspml.xml";

This made no difference. Which ever directory I put them in, it seems to be finding the XML message fine, and three of the xml schemas it requires. It just doesn't seem to resolve the last XML Signature schema ... :cry:

Also, where have you got Xerces-J 2.7.2 from? I thought 2.7.0 was the latest version available from here:

http://www.apache.org/dist/xml/xerces-j/

Cheers,

Sam.
samwise
Posts: 9
Joined: Tue Jul 12, 2005 9:42 pm

RE: Can't duplicate Oxygen's validation using Xerces-J 2.7.0

Post by samwise »

Just to conclude this thread.

Xerces-J 2.7.0 is the latest at time of writing, as I thought.

George has been kind enough to help me outside the forum and we eventually discovered that there two further files that were being downloaded off the web. By setting my proxy host & port on the command line, I was able to get the JVM to download them. After writing the code flawlessly up to this point, this was a total D'oh! realisation ... :oops:

My eternal thanks to George for spending so much time on what was really a schoolboy error of mine.

Many thanks!!!

Sam.
raj_yah_raj@yahoo.co.in
Posts: 1
Joined: Tue Apr 11, 2006 11:51 am

Post by raj_yah_raj@yahoo.co.in »

Hi George & Sam,

Iam getting a similar issue when i use

<xs:import namespace="http://www.w3.org/2004/08/xop/include/" schemaLocation="XopInclude.xsd"/>

I get the error
[ Cannot resolve the name 'Include' to a(n) 'element declaration' component. ]

Do u mean that you were getting SAX exception due to the Xerces-J Version ?
Plz help me on solving this issue

Thanks in advance
Have a grt day
Raj
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Raj,

Make sure your XopInclude.xsd is available in the same folder as your schema that imports it and also make sure the parser knows the system identifier for your schema, otherwise it cannot resolve the XopInclude.xsd relative location. Also it may be possible that your schemas do not define the "Include" element or defines it in a different namespace than the namesapce this element has in your instance document or in your schema.

Best Regards,
George
Last edited by george on Tue Apr 11, 2006 12:42 pm, edited 1 time in total.
samwise
Posts: 9
Joined: Tue Jul 12, 2005 9:42 pm

Post by samwise »

Raj,

I think that error may mean that <Oxygen /> (or your java code) isn't finding the schema *and all child schemas* required - at least, that was the problem in my case. By not entering a full path or URL, it will look for XopInclude.xsd in the same directory. Are you sure that you have XopInclude.xsd in the right place, along with any further schemas referenced within XopInclude.xsd?

If your setup needs to download a schema from the web, you need to make sure any proxies etc. are set and there are no firewalls or similar, blocking your internet connection.

HTH,

Sam.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,
raj_yah_raj@yahoo.co.in wrote:Iam getting a similar issue when i use

<xs:import namespace="http://www.w3.org/2004/08/xop/include/" schemaLocation="XopInclude.xsd"/>

I get the error
[ Cannot resolve the name 'Include' to a(n) 'element declaration' component. ]
The error message does not refer to the xs:import element which you posted here because what you posted does not contain any Include reference.

Regards,
Sorin
Post Reply