users@jaxb.java.net

Re: JAXB and xsd:any values

From: jmdev <jhmiller001_at_yahoo.com>
Date: Tue, 28 Apr 2009 13:38:38 -0700 (PDT)

I am using the same spec and am having difficulties with JAXB. I would like
to simply specify a String for the "xsd:any" content

JAXB generates

  @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "any"
    })
    public static class Message {

        @XmlAnyElement(lax = true)
        protected Object any;

        public Object getAny() {
            return any;
        }

        public void setAny(Object value) {
            this.any = value;
        }

    }


And I would simply like to pass:

message.setAny("hello world");

Unfortunately, I receive the cannot marshall a java.lang.String object since
it doesn't have an XmlRootElement.

I tried the solution in this post but it did not seem to solve my problem.
Does anyone have a relatively non invasive means of allowing this? I would
prefer not hacking the OASIS spec, but my understanding is that you cannot
replace complex types in JAXB using the bindings?

Creating a new JAXBElement as follows

JAXBElement<String> jaxb1 = new JAXBElement<String>(new
QName("http://docs.oasis-open.org/wsn/b-2",""), String.class, "hello
world");

also doesn't work for me since I am wrapping my content with another set of
XML tags that have nothing to do with the spec or my message.

Thanks in advance for any help!


Wolfgang Laun-2 wrote:
>
> Additional info:
>
> The prefix xjc must be bund like this:
> xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
>
> Enclose the binding in a binding/schemaLocation element:
> <jxb:bindings schemaLocation="someName.xsd">
> <jxb:bindings node="//xs:any">
> <xjc:dom/>
> </jxb:bindings>
> </jxb:bindings>
>
> -W
> On Fri, Apr 3, 2009 at 7:32 AM, Gary Gregory
> <GGregory_at_seagullsoftware.com>wrote:
>
>> Alejandro:
>>
>>
>>
>> You need to create an XJC binding file which should contain a fragment
>> like:
>>
>>
>>
>> <jaxb:bindings node="//xs:any">
>>
>> <xjc:dom/>
>>
>> </jaxb:bindings>
>>
>>
>>
>> Gary
>>
>>
>> ------------------------------
>>
>> *From:* Alejandro Escalante Medina [mailto:alex.escalante_at_gmail.com]
>> *Sent:* Thursday, April 02, 2009 7:40 PM
>> *To:* users_at_jaxb.dev.java.net
>> *Subject:* JAXB and xsd:any values
>>
>>
>>
>> Hello guys, I am working with jax-ws and jaxb to implement WS-I
>> Notification services.
>>
>> Everything seems to be working except for a small but important problem:
>>
>> The WS-I Notification schema specification defines the Message element as
>> being able to contain <any> content. I understand that can be any
>> well-formed xml. However, when unmarshaling inside my web service, the
>> getAny() method for the message object comes out null every time...
>>
>> Any ideas?
>>
>> The xsd for WS-I Notification is here:
>>
>> http://docs.oasis-open.org/wsn/b-2.xsd
>>
>> I am using this command line to generate types:
>>
>> xjc.sh http://docs.oasis-open.org/wsn/b-2.xsd
>>
>>
>> Thanks in advance...
>>
>> Alejandro Escalante Medina
>> Visita mi página personal en http://weblocked.blogsome.com/
>>
>
>

-- 
View this message in context: http://www.nabble.com/JAXB-and-xsd%3Aany-values-tp22860952p23285583.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.