users@jaxb.java.net

Problem marshalling part of a xml msg

From: Frank <fgeck_at_optonline.net>
Date: Thu, 19 Oct 2006 20:51:13 -0400

I have a problem and I don't know how to approach it. Not sure jaxb is
the solution may have to use DOM. I have a xml msg that has a complex
element that can accept any thing. I want to pull that out and create
another xml msg, should be easy right? Here is an example schema and
document but I get an error:

[com.sun.istack.SAXException2: unable to marshal type
"csds.message.ReleaseRequest$Item" as an element because it is missing
an @XmlRootElement annotation]


code segment that generated that error
---------------------------------
            JAXBContext context = JAXBContext.newInstance("csds.message");
            csds.message.ObjectFactory objFact = new
csds.message.ObjectFactory();
            ReleaseRequest.Item ddsMsgItem =
objFact.createReleaseRequestItem();
            ReleaseRequest.Item rrI = (ReleaseRequest.Item)
RelReq.getItem();
            ddsMsgItem.setAny(rrI);
            StringWriter result = new StringWriter();
            Marshaller m =context.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            m.marshal( new JAXBElement(new QName("uri","local"),
                                       ReleaseRequest.Item.class,
ddsMsgItem), result);
             
Now if I do the following, no marshal error but the document is not well
formed, it leaves the name spaces before the now what I want new root
element.
 
            StringWriter result = new StringWriter();
            Marshaller m = jc.createMarshaller();
            m.marshal( new JAXBElement(new QName("",""),
                                       ReleaseRequest.Item.class, rrI),
result);

result:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><
xmlns:ns2="urn:us:gov:dod:army:cerdec:jbfsa:csds:r1"><ns3:advertiseSS
advertisementID="1b094a9d-063b-409b-8a3b-923061a5c983"
commandDateTime="2006-05-25T09:49:56.593-04:00" userID="peer"
xmlns:ns3="http://mitre.org/DDS"><ns3:returnAddress>http://128.96.185.16:8080/DDS/services/DDS</ns3:returnAddress><ns3:sourceAddress>http://128.96.185.16:8080/DDS/services/DDS</ns3:sourceAddress><ns3:metadata><ns1:title
ns5:classification="U" ns5:ownerProducer="USA"
xmlns:ns1="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
xmlns:ns5="urn:us:gov:ic:ism:v2">MCS_DEMO</ns1:title><ns4:description
ns5:classification="U" ns5:ownerProducer="USA"
xmlns:ns4="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
xmlns:ns5="urn:us:gov:ic:ism:v2">MCS_Desc</ns4:description><ns5:creator
ns6:classification="U" ns6:ownerProducer="USA"
xmlns:ns5="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
xmlns:ns6="urn:us:gov:ic:ism:v2"><ns5:Organization><ns5:name>MCS</ns5:name></ns5:Organization>
</ns5:creator><ns7:subjectCoverage
xmlns:ns7="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"><ns7:Subject><ns7:category
ns7:label="Ground"/><ns7:keyword ns7:value="MCSAdv1"/>
</ns7:Subject>
</ns7:subjectCoverage><ns8:temporalCoverage
xmlns:ns8="http://mitre.org/DDS/metadata"><ns8:start>2006-05-25T09:38:10-04:00</ns8:start><ns8:end>2006-05-25T14:38:10-04:00</ns8:end></ns8:temporalCoverage><ns9:geospatialCoverage
xmlns:ns9="http://mitre.org/DDS/metadata"><ns9:lowerCorner>-170.0
46.0</ns9:lowerCorner><ns9:upperCorner>-169.0 47.0</ns9:upperCorner>
</ns9:geospatialCoverage><ns10:security ns11:classification="U"
ns11:ownerProducer="USA" xmlns:ns11="urn:us:gov:ic:ism:v2"
xmlns:ns10="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"/><ns12:identifier
ns12:qualifier="Test" ns12:value="value"
xmlns:ns12="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"/>
</ns3:metadata><ns3:hopCount>1</ns3:hopCount>
</ns3:advertiseSS></>

the original document:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:releaseRequest xmlns="urn:us:gov:dod:army:cerdec:jbfsa:csds:r1"
xmlns:ism="urn:us:gov:ic:ism:v2"
xmlns:ns1="urn:us:gov:dod:army:cerdec:jbfsa:csds:r1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:us:gov:dod:army:cerdec:jbfsa:csds:r1
C:\data\JBFSA\r1\csds_src\config\csds_msgs.xsd">
    <ns1:Time>2001-12-17T09:30:47.0Z</ns1:Time>
    <ns1:Item>
    <ns2:advertiseSS
advertisementID="1b094a9d-063b-409b-8a3b-923061a5c983"
commandDateTime="2006-05-25T09:49:56.593-04:00" userID="peer"
xmlns="http://mitre.org/DDS" xmlns:ns2="http://mitre.org/DDS">
<ns2:returnAddress>http://128.96.185.16:8080/DDS/services/DDS</ns2:returnAddress>
<ns2:sourceAddress>http://128.96.185.16:8080/DDS/services/DDS</ns2:sourceAddress>
<ns2:metadata>
<ns1:title ns2:classification="U" ns2:ownerProducer="USA"
xmlns:ns1="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
xmlns:ns2="urn:us:gov:ic:ism:v2">MCS_DEMO</ns1:title>
<ns3:description ns4:classification="U" ns4:ownerProducer="USA"
xmlns:ns3="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
xmlns:ns4="urn:us:gov:ic:ism:v2">MCS_Desc</ns3:description>
<ns5:creator ns6:classification="U" ns6:ownerProducer="USA"
xmlns:ns5="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
xmlns:ns6="urn:us:gov:ic:ism:v2">
<ns5:Organization><ns5:name>MCS</ns5:name></ns5:Organization>
</ns5:creator>
<ns7:subjectCoverage xmlns:ns7="http://metadata.dod.mil/mdr/ns/DDMS/1.2/">
<ns7:Subject><ns7:category ns7:label="Ground"/>
<ns7:keyword ns7:value="MCSAdv1"/>
</ns7:Subject>
</ns7:subjectCoverage>
<ns8:temporalCoverage
xmlns:ns8="http://mitre.org/DDS/metadata"><ns8:start>2006-05-25T09:38:10-04:00</ns8:start><ns8:end>2006-05-25T14:38:10-04:00</ns8:end></ns8:temporalCoverage>
<ns9:geospatialCoverage xmlns:ns9="http://mitre.org/DDS/metadata">
<ns9:lowerCorner>-170.0 46.0</ns9:lowerCorner><ns9:upperCorner>-169.0
47.0</ns9:upperCorner>
</ns9:geospatialCoverage>
<ns10:security ns11:classification="U" ns11:ownerProducer="USA"
xmlns:ns10="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
xmlns:ns11="urn:us:gov:ic:ism:v2"/><ns12:identifier
ns12:qualifier="Test" ns12:value="value"
xmlns:ns12="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"/>
</ns2:metadata>
<ns2:hopCount>1</ns2:hopCount>
</ns2:advertiseSS>

    </ns1:Item>
</ns1:releaseRequest>




The schema segment is as follows (I just want what's in the Item element):
<xsd:element name="releaseRequest">
        <xsd:annotation>
            <xsd:documentation>
    Message from DBS to external MeSH on a domain export
    </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="Time" type="xsd:dateTime"/>
                <xsd:element name="Item">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:any namespace="##any"
processContents="strict"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>