Hello,
I am having problems combining xml schemas from different namespaces, and then
parsing instance documents. Any help would be super!
Firstly I created a schema in my own namespace. I can combine several schema files
using XMLSchema include. I can easily parse my instance documents
using SAXLocalNameCount.java that comes with the WSDP. No problems so far.
At this stage I wanted to start signing and later encrypting elements. So I modified my
original schema to include
<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd" />
and
<import namespace="http://www.w3.org/2001/04/xmlenc#" schemaLocation="http://www.w3.org/TR/xmlenc-core/xenc-schema.xsd" />
I then used elements from xmldsig-core-schema.xsd and xenc-schema.xsd as needed.
I modified my instance documents by adding the new namespace support
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
Again everything parsed fine using SAXLocalNameCount.java. Everything still fine!
Next I decided that I would prefer to use my local copies of the w3.org schemas rather
than contacting their site all the time. (I know that SAXLocalNameCount.java is
doing this because if I remove my proxy configuration from the java command line I
get:
Warning: URI=null Line=32: src-import.0: Failed to read imported schema document �http://www.w3.org/TR/xmlenc-core/xenc-schema.xsd�.
Exception in thread "main" org.xml.sax.SAXException: Error: URI=null Line=121: src-resolve: Cannot resolve the name 'xenc:EncryptedDataType' to a(n) type definition component. at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1092) at SAXLocalNameCount.main(SAXLocalNameCount.java:251)
.)
So I modified SAXLocalNameCount.java as shown below (All files in the same
directory):
if (schemaSource != null)
{
Object[] mySchemas = new Object[3];
mySchemas[0] = new File(schemaSource);
mySchemas[1] = new File("xenc-schema.xsd ");
mySchemas[2] = new File("xmldsig-core-schema.xsd");
saxParser.setProperty(JAXP_SCHEMA_SOURCE, mySchemas);
}
My new SAXLocalNameCount.java compiles fine. If I run it with the proxy then
everything is fine. However I still get the same exception as above when I run it
without using my proxy. This indicates to me that it is NOT using my local copy
of the schema.
Yet if I delete my local copies of xenc-schema.xsd and xmldsig-core-schema.xsd
I now get:
Exception in thread "main" org.xml.sax.SAXException: Error: URI=file:/D:/temp/TLSML/t/tlsml3.xml Line=4: schema_reference.4: Failed to read schema document 'xenc-schema.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1092) at SAXLocalNameCount.main(SAXLocalNameCount.java:261)
So it appears that I now need both my local copy, and the remote copy!
I am certain that I must be making some small mistake. My files are all listed below.
Any help would be greatly
appreciated!
Thanks!
My schema
=========
<?xml version="1.0" encoding="iso-8859-1"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
targetNamespace="http://my.domain.com/docs/TLSML"
elementFormDefault="qualified"
attributeFormDefault="qualified">
<import namespace="http://www.w3.org/2001/04/xmlenc#"
schemaLocation="http://www.w3.org/TR/xmlenc-core/xenc-schema.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" />
<element name="TLSML">
<complexType>
<sequence>
<element name="sessionID" type="string" />
<element name="Content">
<complexType>
<sequence>
<!-- Ciphertext -->
<element name="ciphertext" type="xenc:EncryptedDataType" />
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
<?xml version="1.0" encoding="iso-8859-1"?>
<TLSML xmlns="http://my.domain.com/docs/TLSML"
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<sessionID>123456789</sessionID>
<Content>
<ciphertext Type="http://www.w3.org/2001/04/xmlenc#Content">
<xenc:CipherData>
<xenc:CipherValue>
43sEpGsrriIgJV3X8WMA4cFkbbVz++qV65ujFFoIWwa+rcfOhQ8DDqABoyyYJdG
TOtfd7qEQtPp2P/rqb/bLsHb45U+f76ZXPeV6vTauSV8w8wyoVZVHXBUFDmar8M
4ENtfFlOF1lCa5lclbHYVrGKuLb+okKSsIYQX3PKm0OGXb3mtQyCzblUfXfi+UW
2ctnPuKGdeQXMYyCUvXXDGnCUZX3meGViTZxPCMPZz+fSCOgKgzm9HFJuxITUdS
AoZMz5M+BGMEHzg8HZkyiUks8AqPwd+2h7JVVg1NcetgE929er2Rla9FWjTwiZr
aRdQUhGRErGQgxgL61l4popqIvdetItN3l2+RFiSfKnRXm/bRN0UkTV5h+vhmm/
WTOEID6dncH1QVufVS9VNkJbC9h1VeLL7dgdDCDwjaDHcB/JpblTb/a6t75d/rJ
N2sGRHg5B+tbN73DFSPPz9HUq5nYA7sbO6HwDvNm1B0+HwX1wg8FtpuvfzmT4l/
</xenc:CipherValue>
</xenc:CipherData>
</ciphertext>
</Content>
</TLSML>