Actually, I am new to Castor and right now analyzing the marshalling-unmarshalling feature of Castor. And joined this mailing-list recently. So I apologize if anyone find this obvious.
I found one message on the same issue here - http://www.mail-archive.com/[email protected]/msg10882.html but it has no response as yet. So posting it again with my observations. I too experienced the same and I have couple of observations on this.
While playing around with the castorbuilder.properties file, I found that this happens when you are using the 'type' for the key org.exolab.castor.builder.javaclassmapping in properties file.
I have the following schema -
Schema - 1 - test.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
xmlns = "http://www.foo.com/CommonSchema"
targetNamespace = "http://www.foo.com/CommonSchema"
elementFormDefault = "qualified">
<xsd:element name="status" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="code" type="xsd:integer" />
<xsd:element name="message" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Schema - 2 - test1.xsd - this has imported the above schema.
<?xml version="1.0"?>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
xmlns:cs = "http://www.foo.com/CommonSchema"
xmlns = "http://www.foo.com/mySchema"
targetNamespace = "http://www.foo.com/mySchema"
elementFormDefault = "qualified">
<xsd:import namespace="http://www.foo.com/CommonSchema" schemaLocation="test.xsd" />
<xsd:element name="response">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="cs:status" />
<xsd:element name="data" type="xsd:string" maxOccurs="1" default="Hello World!" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
If I generate the classes using the 'type' method and marshal it, the XML generated is as follows -
<?xml version="1.0" encoding="UTF-8"?>
<response xsi:schemaLocation="http://www.foo.com/mySchema test1.xsd"
xmlns:cs="http://www.foo.com/CommonSchema"
xmlns="http://www.foo.com/mySchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<status>
<cs:code>100</cs:code>
<cs:message>Success</cs:message>
</status>
<data>New Data</data>
</response>
Note that, the 'status' is referring to default schema, 'mySchema', which should actually point to 'CommonSchema'. The statements, xsi: schemaLocation .. etc are there because I set them explicitly in the Marshaller object before marshalling.
Now if I try to parse this XML, the SAX parser throws an exception with message -
Element type "status" must be declared.
If I manually edit the status element and put the prefix 'cs:' before the 'status' then it passes the parsing.
When I looked into the generated descriptor class, then for status field I found that the namespace used is the default namespace - 'mySchema'
Here is the code snippet of it -
//-- _status
desc = new XMLFieldDescriptorImpl(com.foo.common.Status.class, "_stattus", "status", NodeType.Element);
handler = (new XMLFieldHandler() {
...
// Field handler code here..
...
} );
desc.setHandler(handler);
desc.setNameSpaceURI("http://www.foo.com/mySchema");
desc.setRequired(true);
desc.setMultivalued(false);
addFieldDescriptor(desc);
All this happens when I use the 'type' method.
But if I use 'element' - the default for value of org.exolab.castor.builder.javaclassmapping properties of the Source Generator then everything wirks fine, it generates the right XML the field descriptor also has the correct namespace - 'CommonSchema', used for the status field descriptor.
I feel that it should refer to the proper namespace in the XML whatever the method used. I don’t know whether this is a bug or is a desired behavior OR my understanding is worng.
Any comment on this is highly appreciated.
Thanks in advance,
Vinay.
The new MSN 8: smart spam protection and 3 months FREE*. ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
