JAXB and IdRef

K

kevkev

Hi,

I'm new to Sun's JAXB and I having a problem unmarshalling an XML
attribute of type IdRef. When I try to print it out I get a reference
to the object rather than the value of the attribute.

Something like "com.kbilly.cmm.jaxb.cmi.impl.ProductElementImpl@9a8a68"

Do you know how i get the value of the attribute as a string?

Regards,
Kevin
 
I

iksrazal

kevkev escreveu:
Hi,

I'm new to Sun's JAXB and I having a problem unmarshalling an XML
attribute of type IdRef. When I try to print it out I get a reference
to the object rather than the value of the attribute.

Something like "com.kbilly.cmm.jaxb.cmi.impl.ProductElementImpl@9a8a68"

Do you know how i get the value of the attribute as a string?

Regards,
Kevin

Possibly your schema is not defined to return String - you need to look
at the offending method in the generated source to make sure. Or
perhaps its just that your implementation is wrong. Here's an example
of how I do it:

// _xml is a String
InputSource isXml = new InputSource ((InputStream) new
ByteArrayInputStream (_xml.getBytes ()));
JAXBContext jc =
JAXBContext.newInstance("gov.infoseg.mr.xtrans.schemas.consulta_detalhes");
Unmarshaller umd = jc.createUnmarshaller();

gov.infoseg.mr.xtrans.schemas.consulta_detalhes.ConsultaDetalhes
cdetalhes =
(gov.infoseg.mr.xtrans.schemas.consulta_detalhes.ConsultaDetalhes)umd.unmarshal(isXml);

String cd_transacao = cdetalhes.getCdTransacao();

HTH,
iksrazal
http://www.braziloutsource.com/
 
I

iksrazal

Oops, posted before coffee. You want to get an Attribute. Those are
typically done with getters and setters. Basically same reply though -
use the (auto-generated) source, luke!

iksrazal
 
K

kevkev

Thanks for your help!

I've sorted it with a configuration document.

What I needed in my JAXB configuration document is

<jxb:bindings
node="//xs:complexType[@name='IdRef']/xs:attribute[@name='elementId']">
<jxb:property>
<jxb:baseType>
<jxb:javaType
name="java.lang.String"
parseMethod="javax.xml.bind.DatatypeConverter.parseString"
printMethod="javax.xml.bind.DatatypeConverter.printString"/>

</jxb:baseType>
</jxb:property>
</jxb:bindings>

That allows me to get a String object of the value in the elementId
attribute.

Hope this helps someone else who might have a similiar problem, but
don't forget <jxb:baseType> tags like I did! Hours of pain.

Regards,
Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,255
Members
46,852
Latest member
CarlaDowle

Latest Threads

Top