users@jaxb.java.net

Re: JAXB and xsd:any values

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Wed, 29 Apr 2009 10:50:33 +0200

In the creation of the JAXBElement, the constructor for QName ought to have
a second parameter (for localPart) that is not the empty string; this will
define the XML tag for your string.

If this isn't what you want, please show an example for the XML content you
want to have in place of the xs:any.

-W

On Tue, Apr 28, 2009 at 10:38 PM, jmdev <jhmiller001_at_yahoo.com> wrote:

>
> 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.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>