Hello!
I have managed to successfylly alter my schema files to remove all the
redundant namespace declarations from the response XML.
(test schemas are found here:
http://www.codecomments.com/Castor/message495418.html)
What I did was:
1) move ArrayElement and ArrayOfArrayElements from MyService.xsd to
myservicecommon.xsd
2) using "ref" for extensionBaseElement2 instead of "name". In other
words:
a) declare following in common.xsd
<xsd:element name="extensionBaseElement2"
type="common:GeneralAddressType"/>
b) re-declare extensionBaseElement2 in extensionBaseElement in
myservicecommon.xsd
from
<xsd:element name="extensionBaseElement2"
type="common:GeneralAddressType" minOccurs="0"/>
to
<xsd:element ref="common:extensionBaseElement2"
minOccurs="0"/>
The Response XML now looks like this:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<MyServiceResponse
xmlns="http://www.test.com/webservices/service">
<MyServiceResponseWrapper
xmlns="http://www.test.com/webservices/service">
<ns1:elementOne
xmlns:ns1="http://www.test.com/webservices/common">
<ns1:child1>0</ns1:child1>
<ns1:child2>0</ns1:child2>
<ns1:child3>0</ns1:child3>
<ns1:child4>0</ns1:child4>
</ns1:elementOne>
<ElementTwo>
<elementTwoResponseArray>
<arrayElement
xmlns:ns2="http://www.test.com/webservices/service/common">
<ns2:baseElement1>test text</ns2:baseElement1>
<ns2:baseElement2>888</ns2:baseElement2>
<ns2:baseElement3>test text</ns2:baseElement3>
<ns2:extensionBaseElement1>12345678910</ns2:extensionBaseElement1>
<ns3:extensionBaseElement2
xmlns:ns3="http://www.test.com/webservices/service/common">
<ns3:Addr1>test text</ns3:Addr1>
<ns3:Addr2>test text</ns3:Addr2>
<ns3:Zip>0000</ns3:Zip>
<ns3:City>City</ns3:City>
</ns3:extensionBaseElement2>
<ns2:simpleElementOne>1234567</ns2:simpleElementOne>
<ns2:simpleElementTwo>1234567</ns2:simpleElementTwo>
</arrayElement>
</elementTwoResponseArray>
</ElementTwo>
</MyServiceResponseWrapper>
</MyServiceResponse>
</soapenv:Body>
</soapenv:Envelope>
And the Client Portal is hopefully more happy with this!
Any coments on the schema changes and/or the way Source Generator
interpret the original schemas are welcome.. :o)
Cheers,
Are T. Tysnes
-----Original Message-----
From: Gregory Block [mailto:[EMAIL PROTECTED]
Sent: 14. mai 2005 18:51
To: [email protected]
Cc: [email protected]
Subject: [castor-user] Re: [castor-dev][XML] too many namespace
declarations in element attributes
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