This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pradeep Bhat
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<?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
Sheriff
Pie
Posts: 20769
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic