Daniel Dyer wrote:
Hi, just a couple of quick questions about XML mapping.
Firstly, can Castor map XML elements to inner classes (obviously they would have to be public static inner classes), or just to normal, top-level classes?
Yes as long as they are public and static as you mentioned. There is a small gotcha though, the DTD limits the string to an NMTOKEN and you need to use "$" to separate the inner class. I need to support "." for that, but right now you need to "$" so you can't specify the DTD or the XML parser will complain about the "$" (eg: Foo$Bar);
Secondly, what is the status of support for nillable elements? I know there is something in Castor (maybe just in the CVS version?), because I've been reading through the source and bug reports and have seen some discussion about it. Can I map a null field to a nil element like this:
<myElement xsi:nil="true" />
The nillable support is currently only supported via source generated code. We haven't added yet support to specify nillable to the mapping files. Though you might be able to obtain a handle on the in-memory XMLFieldDescriptor by jumping through a few hoops (either via the Mapping->MappingResolver, or via ClassDescriptorResolver) and then calling the setNillable(true) method.
And on a related note, if I have a field mapping like this:
<field name="myField" required="false"><bind-xml location="myWrapper"></field>
I get the following fragment when myField is null:
<myWrapper />
Can I get Castor to omit the myWrapper part, which doesn't map to a field, if there's nothing in it?
hmmmm...I just took a look at the code in Marshaller.java (line 1616 in my version):
if (obj == null) {
if (elemDescriptor.isNillable() && (elemDescriptor.isRequired())) {
nil = true;
}
else continue;
}So it shouldn't print out the wrapper for null elements, though there may be a case when it does, I'll have to look more closely tomorrow.
--Keith
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
