aspose file tools*
The moose likes XML and Related Technologies and the fly likes Castor : Is there any way to get back the namespaces when I unmarshal the object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Castor : Is there any way to get back the namespaces when I unmarshal the object " Watch "Castor : Is there any way to get back the namespaces when I unmarshal the object " New topic
Author

Castor : Is there any way to get back the namespaces when I unmarshal the object

Pradeep Bhat
Greenhorn

Joined: Jan 12, 2008
Posts: 29
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:emt="http://pb123:1400/student/student.xsd" targetNamespace="http://pb123:1400/student/student.xsd">


I have given this in the beginning of the mapping xsd file which i use to generate
java classes using castor(version 1.05 to be specific).


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:emt="http://pb123:1400/student/student.xsd" .....other namespace declarations.....
targetNamespace="http://pb123:1400/student/student.xsd">


Different elements of the xml are in different namespaces (each in different packages).
I have given the mapping package names by using the
org.exolab.castor.xml.nspackages attribute in castorbuilder.properties.

To ensure that the java files get generated in their respective folders,
"elementFormdefault=qualified" is used in the schema definition.
Now the java classes are generated in respective folders.


Now when I unmarshal the object to the xml, is there any way to get back the namespaces.
Because presently i am not getting any namespace definitons in the xml
But the tags appear with prefixes like n1, n2 etc. without namespace
definitons at the beginning of the xml
<ns4:StudenId>1</ns4:StudenId>

How can I get the namespace at the beginning of the xml??
Also why can't i get the same namespace that i defined in the xsd(schema) when I unmarshal.


Regards,
Pradeep.
[ December 13, 2008: Message edited by: Pradeep Bhat ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

If you are getting elements with namespace prefixes that aren't declared, then that's a bug. But I doubt that such a large and obvious bug would still exist in Castor. Could be wrong though. What does the Castor web site say about that?

And when you do get correct namespace declarations, what matters is that the namespace URI is correct. The namespace prefix is arbitrary and doesn't matter.
Pradeep Bhat
Greenhorn

Joined: Jan 12, 2008
Posts: 29
The problem is something like this:

To ensure that the java files get generated in their respective folders,
"elementFormdefault=qualified" needs to be used in the schema definition
else the java files get generated in the same folder.

But doing that results in incremental ns-prefixes ns1,ns2 etc in the tags.
but no namespace uri appear at the beginging of the xml for these prefixes which results in an invalid xml.
(This happens during unmarshalling)....

I was checking out the castor documentation.....
I didn't find mention of anything like it yet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Castor : Is there any way to get back the namespaces when I unmarshal the object