access values in <JAXBElement><? extends

A section of the XML looks like this:

<DocumentIds>

<CustomerDocumentId>

<Id>7777</Id>

<Revision>Orginal</Revision>

</CustomerDocumentId>

</DocumentIds>

The schema shows:

<xs:element name="CustomerDocumentId" type="PartyDocumentId" substitutionGroup="DocumentIdType"/>

I'm assuming that the substitutionGroup causes the xjc to create a DocumentIdType class but not a CustomerDocumentId class.

The getId() and getRevision() methods are in this DocumentIdType class. The getDocumentIdType() method in the DocumentIds class and returns a List<JAXBElement><? extends DocumentIdType>> object. I can't figure out how to get the Id and Revision values after I unmarshall the XML. It marshalls back out OK because I tried that, so there must be someway to get to these values. Reading section 5.5.5 of the JAXB 2.0 specification and the related references I can see why the class is associated with the element property and not the value but I could find no examples to show how to get to the values. Here's what I tried so far:

PurchaseOrderHeader poh = npo.getHeader();

DocumentIds dids = poh.getDocumentIds();

List<JAXBElement><? extends DocumentIdType>> didt = dids.getDocumentIdType();

for(Iterator iterDIDT = didt.iterator(); iterDIDT.hasNext();)

{

try

{

DocumentIdType ndidt = (DocumentIdType)iterDIDT.next();

System.out.println("Cust PO#: " + ndidt.getId());

This gives me a ClassCastException. So I changed it to:

JAXBElement ndidt = (JAXBElement)iterDIDT.next();

This worked but, of course, there was no getId() method. However, if I inserted a line to get the QName value of the JAXBElement I came up with "CustomerDocumentId". Not that this helps any but it shows that this class doesn't have values it has properties.

Anybody know how to get the Id and the Revision values while in the iteration of the List?

[2048 byte] By [icoman2ua] at [2007-10-2 17:29:44]
# 1
This forum software is putting extra ">" in my sample.It reads "<JAXBElement><?"and it s/b "<JAXBElement><?"
icoman2ua at 2007-7-13 18:46:28 > top of Java-index,Java Essentials,Java Programming...