Can't tell you if it's source generator or not, but I routinely use Castor to generate XML without having any messy namespace problems.
The trick, I believe, is to make sure that you report to the marshaller object all of those namespaces you wish to use and map, and ensure
that all of the appropriate namespaces are present in your mapping files.

But I don't use SourceGenerator, and can't tell you whether or not it behaves differently; I suspect not, unless you're using the built-in marshal() methods, in which case, my advice is "Don't Do That".� :)

From my "XMLManager" service in my current codebase:

� �� �� �� �� �� �� �� �// Attach schemas.
� � � � � � � � � � � � if (schemaLocation!=null) { m.setSchemaLocation(schemaLocation); }
� � � � � � � � � � � � if (nnschemaLocation!=null) { m.setNoNamespaceSchemaLocation(nnsch
emaLocation); }
� � � � � � � � � � � � if (rootElement!=null) { m.setRootElement(rootElement); }
� � � � � � � � � � � � // Configure namespace mappings.
� � � � � � � � � � � � try {
� � � � � � � � � � � � � � � � Config namespaceCfg = cf.getConfig(cfg, xmlNamespaceKey);
� � � � � � � � � � � � � � � � Map map = namespaceCfg.getMap();
� � � � � � � � � � � � � � � � if (map!=null) {
� � � � � � � � � � � � � � � � � � � � Iterator it = map.keySet().iterator();
� � � � � � � � � � � � � � � � � � � � while(it.hasNext()) {
� � � � � � � � � � � � � � � � � � � � � � � � String key = (String)it.next();
� � � � � � � � � � � � � � � � � � � � � � � � m.setNamespaceMapping(key, (String)map.get
(key));
� � � � � � � � � � � � � � � � � � � � }
� � � � � � � � � � � � � � � � }
� � � � � � � � � � � � } catch (ConfigNotFoundException e) {
� � � � � � � � � � � � � � � � // Not an error.
� � � � � � � � � � � � }
� � �� �� �� �� �� �� �
Just make sure that whenever you have namespaces which are in need of configuring, they're provided to the unmarshaller.� The config, in this case, contains a 'map' structure, where key is the namespace to use, and the value is the actual namespace url.

So, in general, when I marshal hand-rolled objects (we never use SourceGen)
�1) setSchemaLocation()
�2) setNoNamespaceSchemaLocation() when appropriate
�3) add namespace mappings via setNamespaceMapping(ns, url).
�4) Fire and forget.

Should Just Work (TM).


Sending to [email protected] as well, as I've seen someone else mention this recently...

On 14 May 2005, at 13:34, Tysnes Are Thobias wrote:


Hello Castor Developers!

Would be happy if one developer with knowledge of Castor would help me solve this issue which I suspect is a feature og the XML Source Generator

http://archive.codehaus.org/castor/user/msg00460.html

The client for our Web Services is BEA WebLogic Portal and they tell me that the Portal uses 1GB of memory to parse a response containing 6000 lines.. most of the lines are attributes with new namespace declarations shown in the test-example above.

I haven't confirmed this myself but anyways I have to clean the response XML. I don't see any reason for all these namespace declarations on the attributes.

I will be willing to spend some time solving this issue and fix the Source Generator (if neede).

So.. It would be nice if someone could confirm this to be an issue with the Sorce Generator. Nothing would make me more happy than someone saying I'm using the tools in a wrong way or if there is some errors in my schema :o)

Cheers,
Are T. Tysnes


Reply via email to