Hi Kirk,
As I mentioned in my earlier post this has been reported before. I
decided to take a quick look into it...
I coded up an example which uses your code from below...it unmarshals
properly for me.
It doesn't marshal properly because the namespace is never used, so
there are bugs, but at it does unmarshal.
There are definately bugs in the processAttributes method with respect
to namespace handling, however it unmarshals properly because if it
can't find the attributes, it strips off the prefix and looks for a
matching descriptor. Not the best approach. It should pass in the
namespace URI when looking for descriptors, but at least it does find
the correct descriptor because there is only one descriptor with the
"schemaLocation" name.
In any case, we'll get that code cleaned up before 0.9.4.
--Keith
Kirk Wolf wrote:
>
> Laslo,
>
> Thanks for the suggestion, but root namespace qualfication doesn't help if I
> can't unmarshall the schemaLocation.
>
> I apologize as I'm a newbie with Castor, but from what I can determine,
> namespace handling of attributes doesn't work as I would expect. I tried to
> capture xsi:schemaLocation by adding the following to my descriptor:
>
> //-- handle xsi:schemaLocation
> XMLFieldDescriptorImpl desc = new
> XMLFieldDescriptorImpl(java.lang.String.class, "schemaLocation",
> "schemaLocation", NodeType.Attribute);
> desc.setImmutable(true);
> XMLFieldHandler handler = (new XMLFieldHandler() {
> ...
> } );
> desc.setHandler(handler);
> desc.setNameSpaceURI("http://www.w3.org/2001/XMLSchema-instance");
> desc.setRequired(true);
> addFieldDescriptor(desc);
>
> This doesn't work because the method UnMarshalHandler.processAttributes()
> has the following line:
>
> String attValue = atts.getValue(attName);
>
> But attName is the unqualified name ("schemaLocation"), so the descriptor
> doesn't match the (qualified) attribute. It seems to me that there is a bug
> in this method, which I think should read:
>
> String attValue
> = atts.getValue(descriptor.getNamespaceURI(), attName);
>
> As it stands now, it doesn't seem to me that the UnMarshaller can support a
> namespace qualified attribute, since the XMLFieldDescriptor namespaceURI is
> ignored.
>
>
>
> Kirk Wolf
>
> BEDNARIK,LASLO (HP-Germany,ex1) writes:
>
> > Hi Kirk,
> >
> > from what I read on this list so far the schemaLocation is currently not
> > supported (but in the works...). For getting namespace info at the root
> > you have to:
> >
> > - instantiate a Marshaller object yourself (instead of using
> > marshal method of a generated class)
> >
> > - call Marshaller.setNSPrefixAtRoot(true)
> >
> > - call setNamespaceMapping(nsPrefix, nsUri)
> > for all of the namesapces used in your documents
> >
> > That should do the trick.
> >
> > Bye,
> >
> > Laslo
> >
> > ======================================================================
> > _ _ ___ ___ Laslo Bednarik Tel. {0|49}-7031-468-2025
> > | || | _ \/ __| Software Engineer Telnet 701-2025
> > | __ | _/\__ \ Fax {0|49}-7031-468-2207
> > |_||_|_| |___/ 701-2207
> > =========== Hewlett-Packard ============ ___ _____
> > = HP Services IT = |_ _|_ _|
> > = Mail: [EMAIL PROTECTED] = | | | |
> > = http://isoit155.bbn.hp.com/~lbednari = |___| |_|
> > ======================================================================
> >
> >
> > -----Original Message-----
> > From: Kirk Wolf [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, January 30, 2002 4:09 PM
> > To: [EMAIL PROTECTED]
> > Subject: [castor-dev] [XML] how to unmarshal and marshal
> > xsi:schemaLocation
> >
> >
> > I used the SourceGenerator to generate classes from an W3C schema.
> > When I unmarshall and marshall an instance document using the generated
> > classes and descriptor classes, the marshalled document does not include the
> >
> > xsi:schemaLocation attribute (nor the xsi: namespace declaration).
> > Is there a way to round-trip this information?
> >
> > Thanks,
> > Kirk Wolf
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> > unsubscribe castor-dev
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> > unsubscribe castor-dev
> >
>
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev