users@jaxb.java.net

Re: problem marshalling from prefixed data

From: Dmitri Colebatch <dim_at_colebatch.com>
Date: Wed, 22 Mar 2006 22:34:19 +1100

Hi Jason,

I don't know enough about the details of the interaction of DTDs,
prefixes, and namespaces to give you an accurate answer to your
question. However I can offer you a potential solution.

In short, JAXB is seeing an element it isn't aware of (ff:DataSet) and
ignoring it. You can see this by adding the following code
immediately after creating the Unmarshaller:

    u.setEventHandler(new ValidationEventHandler()
    {
            public boolean handleEvent(ValidationEvent event)
            {
                    System.out.println(event);
                    return true;
            }
    });

For me it spits out this:

utility data: FFD
[severity=ERROR,message=unexpected element
(uri:"http://www.newyorkfed.org/xml/schemas/FF/utility",
local:"DataSet"). Expected elements are
<{}DataSet>,<{}Header>,locator=[node=null,object=null,url=file:/C:/tmp/thingy/original_ffd.xml,line=37,col=14,offset=-1]]
exception: null

Which after looking at UtilityData makes perfect sense. UtilityData
wants an element in the default namespace called "ff:DataSet", as
that's what the annotations say:

  @XmlElement(name = "ff:DataSet")
  protected FfDataSet ffDataSet;

however, in your xml, you have an element ff:DataSet with ff defined
as a namespace alias and so the element is in the namespace
"http://www.newyorkfed.org/xml/schemas/FF/utility" and named
"DataSet". If you edit UtilityData and change the above to:

  @XmlElement(name="DataSet",namespace="http://www.newyorkfed.org/xml/schemas/FF/utility")
  protected FfDataSet ffDataSet;

then it works. However this is generated code, and I'm not sure if
you are in a position to do that.

Like I said at the start, I really dont know enough about which rules
apply when you have namespaces and DTDs and prefixes interoperating,
but to me it looks like JAXB is doing the right thing. My reasoning
there is that JAXB doesn't know anything about your schema or dtd
(lets ignore xjc for a minute), and is simply parsing xml, which in
your case has namespaces, into an appropriately annotated class
structure. I think this part is working fine.

The part I'm not sure about is xjc and/or xmlspy. I really don't know
much about xjc's behaviour in relation to DTDs so wouldn't want to
comment too much, but at a glance it looks like its doing the right
thing. The next question is xmlspy - are you generating that DTD
based on the XML? If so, why don't you try generating a schema
instead? I think you'd find that would simplify the whole thing,
although I assume you have good reason for not doing so. In short, I
don't think the xml conforms to the DTD because the XML has
namespaces, and the DTD does not (again - my knowledge of DTDs and
namespaces is at best 'skinny').

Hope this helps you in some regard.

cheers
dim


On 3/21/06, jason white <jason_white_01_at_hotmail.com> wrote:
> Dmitri,
>
> I finally was able to put together a fairly simple tester class that tests a
> file that has tags that don't have a prefix (which works well), and tags
> that do have prefixes (doesn't work)...
>
> Jar file attached.
>
> Here is the error output:
>
> utility data: FFD
> exception: null
> Exception in thread "main" java.lang.Error: java.lang.NullPointerException
> at
> com.UnmarshallTester.testPrefixedFile_PrefixElement(UnmarshallTester.java:46)
> at com.UnmarshallTester.main(UnmarshallTester.java:17)
> Caused by: java.lang.NullPointerException
> at
> com.UnmarshallTester.testPrefixedFile_PrefixElement(UnmarshallTester.java:42)
> ... 1 more
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>