i'm trying to unmarshall an xml like this:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:b2bHotelSOAP" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getAvailableHotelResponse>
<return xsi:type="ns1:getAvailableHotelResponse">
<responseId xsi:type="xsd:integer">1</responseId>
<searchId xsi:type="xsd:string">HR-47754204</searchId>
<totalFound xsi:type="xsd:integer">20</totalFound>
<availableHotels SOAP-ENC:arrayType="ns1:hotel[20]" xsi:type="ns1:hotelArray">
...
</availableHotels>
</return>
</ns1:getAvailableHotelResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
i'm using that package-info.java to specify the namespace used into soap response:
#XmlSchema(
namespace="http://schemas.xmlsoap.org/soap/envelope/",
elementFormDefault=XmlNsForm.QUALIFIED,
xmlns={
#XmlNs(namespaceURI = "http://schemas.xmlsoap.org/soap/envelope/", prefix = "SOAP-ENV"),
#XmlNs(namespaceURI = "urn:b2bHotelSOAP", prefix = "ns1"),
#XmlNs(namespaceURI = "http://www.w3.org/2001/XMLSchema", prefix = "xsd"),
#XmlNs(namespaceURI = "http://www.w3.org/2001/XMLSchema-instance", prefix = "xsi"),
#XmlNs(namespaceURI = "http://schemas.xmlsoap.org/soap/encoding/", prefix = "SOAP-ENC")
}
)
#XmlAccessorType(XmlAccessType.FIELD)
package com.giove.viaggi.hsw.provider.hotelspro;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
what i need is to unmarshall that soap xml into this bean:
package myPackage;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.oxm.annotations.XmlPath;
#XmlRootElement(name="Envelope")
public class MyBean {
#XmlPath("return/availableHotels/item")
private List<Hotel> hotels;
public List<Hotel> getHotels(){
return this.hotels==null?new ArrayList<Hotel>():this.hotels;
}
}
When i try to unmarshall it using jaxbUnmarshaller it gives me always null for the hotels attribute even if they are present into soap response.
Do i make any mistake?
Can please someone give me an help?
Thanks!
MyBean
Below is what the #XmlPath annotation on your MyBean class should look like. Some things to note:
Your domain class must be in the same package as the package-info class you want applied to it.
When you use #XmlPath you need to include each step in the path, you had left some out.
Namespace qualfifcation in the #XmlPath corresponds to the prefixes you have defined in the #XmlSchema annotation (see: http://blog.bdoughan.com/2010/09/xpath-based-mapping-geocode-example.html).
package com.giove.viaggi.hsw.provider.hotelspro;
import java.util.*;
import javax.xml.bind.annotation.*;
import org.eclipse.persistence.oxm.annotations.XmlPath;
#XmlRootElement(name="Envelope")
public class MyBean {
#XmlPath("SOAP-ENV:Body/ns1:getAvailableHotelResponse/return/availableHotels/item")
private List<Hotel> hotels;
public List<Hotel> getHotels(){
return this.hotels==null?new ArrayList<Hotel>():this.hotels;
}
}
Note
Instead of mapping the MyBean class to the Envelope element I would map it to the local root return and pass it that element to unmarshal instead.
http://blog.bdoughan.com/2012/08/handle-middle-of-xml-document-with-jaxb.html
Related
Is it possible to directly unmarshal a list of wrapped elements into a List<String> in JAXB?
For example I have a XML like:
<TEST>
<MIME_INFO>
<MIME>
<MIME_SOURCE>foo.png</MIME_SOURCE>
<MIME_PURPOSE>normal</MIME_PURPOSE>
</MIME>
<MIME>
<MIME_SOURCE>bar.png</MIME_SOURCE>
<MIME_PURPOSE>normal</MIME_PURPOSE>
</MIME>
</MIME_INFO>
</TEST>
So would it be possible to directly unmarshal this XML file into a List<String> only containing { "foo.png", "bar.png" }?
I know that you could create a class hierarchy with the correct annotations to perform this unmarshalling but i would like to have a code like:
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name = "TEST")
#XmlAccessorType (XmlAccessType.FIELD)
public class Info {
// -> what annotation to put here?
private List<String> infos;
public List<String> getInfos() {
return infos;
}
}
And the main file:
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
public class UnmarshallingJAXB {
public static void main(String[] args) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(Info.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Info info = (Info) jaxbUnmarshaller.unmarshal(new File("test.xml"));
// should output foo.png and bar.png
info.getInfos().forEach(System.out::println);
}
}
Is there any way to do that?
Apologies for answering so late, but this is the first hit on Google if search for related problems so it might help anyway.
Yes, it is possible, using
#XmlElementWrapper
in combination
#XmlElement
See this example for more detailed info.
I have been working hard to make below program work, but there seems to be some serious flaw either in my code or with #XmlPath annotation.
XML that I am trying to parse:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<information>
<customer id="customer1">
<billingAddress id="address1">
<street id="street1">1 Billing Street</street>
<street id="street2">2 Billing Street</street>
</billingAddress>
</customer>
</information>
The Pojo that I am creating:
package parser;
import lombok.ToString;
import org.eclipse.persistence.oxm.annotations.XmlPath;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
#ToString
#XmlRootElement(name = "information")
#XmlAccessorType(XmlAccessType.FIELD)
public class Information {
#XmlPath("customer/#id")//-------------------------------------> (1)
private String customerId;
#XmlPath("customer[#id='customer1']/billingAddress/#id") //-----> (2)
private String billingAddressId;
}
How I am unmarshalling the xml:
import parser.Information;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
public class Main {
public static void main(String[] args) throws JAXBException {
JAXBContext jaxbContext = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[]{Information.class}, null);
Unmarshaller jaxbMarshaller = jaxbContext.createUnmarshaller();
Information information = (Information)jaxbMarshaller.unmarshal(new File("information.xml"));
System.out.println(information);
}
}
Output for the above is:
Information(customerId=null, billingAddressId=address1)
Clearly the output is incorrect. customerId is showing null instead of customer1. However, if I comment out the line (2) in pojo class then the customerId is getting correct value. Why is it so ? Why can't I read the correct customerId value in above program ?
Removing the [#id='customer1'] from the 2nd XmlPath does solve the issue for the provided code, even though I assume the real Information entity has much more fields which you address with XmlPath.
Why don't you use some classes to reflect the XML structure ... kinda like object-oriented? It'll simplify the JAXB modelling.
I have a class which contains an ArrayList(SuperClass) property. Now I wish to unmarshall the following XML file which contains different element names in that collection because these are subclasses of the Superclass. Is there a way of doing this with Moxy?
<?xml version="1.0" encoding="UTF-8"?>
<SmMessageSet xmlns:nav="urn:ccsds:recommendation:navigation:schema:ndmxml:R1.5"
xmlns="urn:ccsds:recommendation:service_management:schema:sccs:R1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ccsds:recommendation:service_management:schema:sccs:R1.0 file:/C:/CCSDS-910.11-B-1_XML_schemas/CCSDS-910.11-B-1_XML_schemas/SmSchema-v1.0.0.xsd">
<sccsSmVersionRef>sccsSmVersionRef0</sccsSmVersionRef>
<smSource>smSource0</smSource>
<smDestination>smDestination0</smDestination>
<serviceAgreementRef>serviceAgreementRef0</serviceAgreementRef>
<smMessages>
<querySpaceCommunicationServiceProfileFailedReturn>
<messageSequenceNumber>50</messageSequenceNumber>
<messageTimestamp>2006-05-04T18:13:51.0</messageTimestamp>
<invocationMessageSequenceNumber>50</invocationMessageSequenceNumber>
<spaceCommunicationServiceProfileRef>spaceCommunicationServiceProfileRef0
</spaceCommunicationServiceProfileRef>
<qscspError>
<erroredItem>erroredItem0</erroredItem>
<diagnostic>operation timeout</diagnostic>
</qscspError>
<qscspError>
<erroredItem>erroredItem1</erroredItem>
<diagnostic>operation timeout</diagnostic>
</qscspError>
</querySpaceCommunicationServiceProfileFailedReturn>
<createUserAccountInvocation1>
<messageSequenceNumber>50</messageSequenceNumber>
<messageTimestamp>2006-05-04T18:13:51.0</messageTimestamp>
<username>createdUser</username>
<password>createdPassword</password>
<firstname>Test</firstname>
<lastname>User</lastname>
<email>test.user#host.de</email>
<role>SCHEDULING_OFFICER</role>
<superuser>0</superuser>
</createUserAccountInvocation1>
</smMessages>
</SmMessageSet>
The querySpaceCommunicationServiceProfileFailedReturn and createUserAccountInvocation are in my java object model subclasses of SmMessage base class, which is held by the SmMessageSet class in an, as above described, ArrayList of SmMessage classes.
I would also like to not change the current XML structure (i.e. create a wrapper element around the SmMessages in the XML file).
Any help would be appreciated :)
You could do the following leveraging #XmlElementWrapper and #XmlElementRef:
Java Model
SmMessageSet
You can use the #XmlElementWrapper annotation to add a grouping element around the collection (see: http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html). You can also use the #XmlElementRef annotation to model the element name as the inheritance indicator (substitution groups in XML Schema, see: http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-substitution.html).
package forum20745762;
import java.util.List;
import javax.xml.bind.annotation.*;
#XmlRootElement(name="SmMessageSet")
#XmlAccessorType(XmlAccessType.FIELD)
public class SmMessageSet {
#XmlElementWrapper
#XmlElementRef
private List<SmMessage> smMessages;
}
SmMessage
JAXB/MOXy won't automatically pull in all subclasses of a class, so you can use the #XmlSeeAlso annotation to have them pulled in.
package forum20745762;
import javax.xml.bind.annotation.XmlSeeAlso;
#XmlSeeAlso({CreateUserAccountInvocation.class, QuerySpaceCommunicationServiceProfileFailedReturn1.class})
public class SmMessage {
}
CreateUserAccountInvocation
One each of the subclasses you need to annotate with #XmlRootElement. This is the element name that the #XmlElementRef annotation will match on.
package forum20745762;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class CreateUserAccountInvocation extends SmMessage {
}
QuerySpaceCommunicationServiceProfileFailedReturn1
package forum20745762;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class QuerySpaceCommunicationServiceProfileFailedReturn1 extends SmMessage {
}
package-info
We will use the package level #XmlSchema annotation to map the namespaces (see: http://blog.bdoughan.com/2010/08/jaxb-namespaces.html).
#XmlSchema(
namespace="urn:ccsds:recommendation:service_management:schema:sccs:R1.0",
elementFormDefault=XmlNsForm.QUALIFIED
)
package forum20745762;
import javax.xml.bind.annotation.*;
Demo Code
Demo
The following demo code will read the XML from your question, and then write it back out.
package forum20745762;
import java.io.File;
import javax.xml.bind.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(SmMessageSet.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
File xml = new File("src/forum20745762/input.xml");
SmMessageSet smMessageSet = (SmMessageSet) unmarshaller.unmarshal(xml);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(smMessageSet, System.out);
}
}
Output
The output below corresponds to just the subset of your XML document that I had mapped to:
<?xml version="1.0" encoding="UTF-8"?>
<SmMessageSet xmlns="urn:ccsds:recommendation:service_management:schema:sccs:R1.0">
<smMessages>
<querySpaceCommunicationServiceProfileFailedReturn1/>
<createUserAccountInvocation/>
</smMessages>
</SmMessageSet>
I have an issue while un-marshalling simple XML (a subset of CSDL) using JAXB.
Someone already tried to assist me in the past (here), however it is partially worked and I don't know what to do...
Please consider the following XML:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="3.0">
<Schema xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration" xmlns:sap="http://www.sap.com/Protocols/SAPData" xmlns="http://schemas.microsoft.com/ado/2009/11/edm" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" Namespace="myNS">
</Schema>
</edmx:DataServices>
</edmx:Edmx>
As I was told, I have a package-info.java file that looks like (in the same package):
#XmlSchema(
namespace="http://schemas.microsoft.com/ado/2007/06/edmx",
elementFormDefault=XmlNsForm.QUALIFIED,
xmlns={
#XmlNs(prefix="edmx", namespaceURI="http://schemas.microsoft.com/ado/2007/06/edmx"),
#XmlNs(prefix="", namespaceURI="http://schemas.microsoft.com/ado/2009/11/edm"),
#XmlNs(prefix="m", namespaceURI="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata")
}
)
#XmlAccessorType(XmlAccessType.FIELD)
package com.sap.ndb.studio.rdl.csdlparser.jaxb.objects;
import javax.xml.bind.annotation.*;
In addition, I have the following data structure:
Edmx.java
package com.sap.ndb.studio.rdl.csdlparser.jaxb.objects;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name = "Edmx")
public class Edmx {
#XmlElement(name = "DataServices")
private DataService dataService;
public DataService getDataService() {
return dataService;
}
}
DataService.java
package com.sap.ndb.studio.rdl.csdlparser.jaxb.objects;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class DataService {
#XmlElement(name = "Schema")
private Schema schema;
#XmlAttribute(name = "DataServiceVersion")
private double version;
public Schema getSchema() {
return schema;
}
}
Schema.java
package com.sap.ndb.studio.rdl.csdlparser.jaxb.objects;
#XmlRootElement
public class Schema {
....
}
Notice: in Schema.java I have some implementation which does not related to the XML so I have took it off (internal logic).
After un-marshalling the XML using the JAXB, The returned Edmx object contains null values both in 'schema' and 'version' members, although I have mentioned all xmlns parameters in my package-info.java.
Anyone? :(
UPDATE
In my answer to one of your previous questions I provider a mapping for the model from this question.
Error while trying to unmarshal EDMX with JAXB
I have updated this answer to address the following comment that you made:
Why should I declare
'namespace=schemas.microsoft.com/ado/2009/11/edm'; in my #XmlElement?
sorry for being annoying (this is my first experience with JAXB) but I
just gonna have a long XML with many #XmlElement nodes similar to the
'Schema' and I would like to declare the namespace for them only
once...
You can reduce the number of times you need to declare a namespace by organizing your model classes into different packages based on the namespace that they correspond to.
Package 1 for Namespace http://schemas.microsoft.com/ado/2007/06/edmx
package-info
For each package we will use the #XmlSchema annotation to specify the namespace qualification. In this example we only need to specify the namespace for this particular package.
#XmlSchema(
namespace="http://schemas.microsoft.com/ado/2007/06/edmx",
elementFormDefault=XmlNsForm.QUALIFIED,
xmlns={
#XmlNs(
prefix="edmx",
namespaceURI="http://schemas.microsoft.com/ado/2007/06/edmx"
),
}
)
#XmlAccessorType(XmlAccessType.FIELD)
package forum14875956.edmx;
import javax.xml.bind.annotation.*;
Edmx
The XML elements corresponding to the Edmx class will be namespace qualified according to what we defined on the #XmlSchema annotation for this package.
package forum14875956.edmx;
import javax.xml.bind.annotation.*;
#XmlRootElement(name = "Edmx")
public class Edmx {
#XmlElement(name = "DataServices")
private DataService dataService;
public DataService getDataService() {
return dataService;
}
}
DataService
The DataService class contains a reference to a class corresponding to a different XML namespace. If the Schema class was in the same package we could use the #XmlElement annotation to override the namespace qualification. Since Schema is in a different package we can use the #XmlElementRef annotation. This tells JAXB to derive the element information from the root element configured for that class.
package forum14875956.edmx;
import javax.xml.bind.annotation.*;
import forum14875956.schema.Schema;
public class DataService {
//#XmlElement(namespace="http://schemas.microsoft.com/ado/2009/11/edm", name="Schema")
#XmlElementRef
private Schema schema;
public Schema getSchema() {
return schema;
}
}
Package 2 for Namespace http://schemas.microsoft.com/ado/2009/11/edm
Again we will use the #XmlSchema to declare the namespace information for the second package.
package-info
#XmlSchema(
namespace="http://schemas.microsoft.com/ado/2009/11/edm",
elementFormDefault=XmlNsForm.QUALIFIED,
xmlns={
#XmlNs(
prefix="",
namespaceURI="http://schemas.microsoft.com/ado/2009/11/edm"
)
}
)
#XmlAccessorType(XmlAccessType.FIELD)
package forum14875956.schema;
import javax.xml.bind.annotation.*;
Schema
The elements in the Schema class will be namespace qualified based namespace information in the #XmlSchema annotation for its package.
package forum14875956.schema;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name="Schema")
public class Schema {
}
ORIGINAL ANSWER
You need to include the namespace URI on the mapping for the schema property:
#XmlRootElement
public class DataService {
#XmlElement(name = "Schema" , namespace="http://schemas.microsoft.com/ado/2009/11/edm")
private Schema schema;
#XmlAttribute(name = "DataServiceVersion")
private double version;
public Schema getSchema() {
return schema;
}
}
Full Example
A little while I ago I answered one of your questions providing a complete mapping for this model:
Error while trying to unmarshal EDMX with JAXB
So, lets say I have this xml with several namespaces.
<Envelope xmlns:pdi="http://www.mypage.com/schemas/pdi" xmlns:ib="http://www.mypage.com/schemas/ib" xmlns="http://www.mypage.com/schemas/envelope">
<Product>
<pdi:number>123456</pdi:number>
</Product>
<Instance>
<ib:serial>abcdefg</ib:serial>
</Instance>
</Envelope>
I'm trying to build a client for it. I have an Envelope POJO that's declared like this
#XmlRootElement(name ="Envelope", namespace = "http://www.mypage.com/schemas/envelope")
public class Envelope
and inside, it has these attributes
#XmlElement(name="Product", namespace = "http://www.mypage.com/schemas/pdi")
public Product getProduct(){...}
#XmlElement(name="Instance", namespace = "http://www.mypage.com/schemas/ib")
public Instance getInstance(){...}
Also, the Product POJO looks like this:
#XmlRootElement(name="Product", namespace = "http://www.mypage.com/schemas/pdi")
public class Product
and attribute
#XmlElement(name="pdi:number", namespace = "http://www.mypage.com/schemas/pdi")
public int getNumber(){...}
For some reason, I can't get the product number. I keep getting a request error. Am I handling the namespaces correctly, or am I missing something?
For this use case I would recommend leveraging the package level #XmlSchema annotation to specify the namespace qualification.
package-info (forum14651918/package-info.java)
#XmlSchema(
namespace="http://www.mypage.com/schemas/envelope",
elementFormDefault=XmlNsForm.QUALIFIED,
xmlns={
#XmlNs(namespaceURI = "http://www.mypage.com/schemas/envelope", prefix = ""),
#XmlNs(namespaceURI = "http://www.mypage.com/schemas/ib", prefix = "ib"),
#XmlNs(namespaceURI = "http://www.mypage.com/schemas/pdi", prefix = "pdi")
}
)
#XmlAccessorType(XmlAccessType.FIELD)
package forum14651918;
import javax.xml.bind.annotation.*;
Envelope (forum14651918/Envelope.java)
Since we have specified a namespace and elementFormDefault on the #XmlSchema annotation, all the elements corresponding to the Envelope class will be automatically qualified with the http://www.mypage.com/schemas/envelope namespace.
package forum14651918;
import javax.xml.bind.annotation.*;
#XmlRootElement(name="Envelope")
public class Envelope {
#XmlElement(name="Product")
private Product product;
#XmlElement(name="Instance")
private Instance instance;
}
Product (forum14651918/Product.java)
You can override the namespace for the Product class using the #XmlType annotation.
package forum14651918;
import javax.xml.bind.annotation.*;
#XmlType(namespace="http://www.mypage.com/schemas/pdi")
public class Product {
private int number;
}
Instance (forum14651918/Instance.java)
You can override the namespace for the Instance class using the #XmlType annotation.
package forum14651918;
import javax.xml.bind.annotation.XmlType;
#XmlType(namespace="http://www.mypage.com/schemas/ib")
public class Instance {
private String serial;
}
Demo (forum14651918/Demo.java)
Below is some code you can run to prove that everything works.
import java.io.File;
import javax.xml.bind.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Envelope.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
File xml = new File("src/forum14651918/input.xml");
Envelope envelope = (Envelope) unmarshaller.unmarshal(xml);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(envelope, System.out);
}
}
For More Information
http://blog.bdoughan.com/2010/08/jaxb-namespaces.html
http://blog.bdoughan.com/2011/11/jaxb-and-namespace-prefixes.html
http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
Try replacing name="pdi:number", namespace = "http://www.mypage.com/schemas/pdi" with name="number", namespace = "http://www.mypage.com/schemas/pdi". Prefix is not needed.
What is more looking at the XML it seems that namespace for both Product and Instance is http://www.mypage.com/schemas/envelope.
You should not need #XmlRootElement annotation for Product class. It is not a root element and is already configured on getProduct().
Full configuration that should be OK is:
#XmlRootElement(name ="Envelope", namespace = "http://www.mypage.com/schemas/envelope")
public class Envelope {
#XmlElement(name="Product", namespace = "http://www.mypage.com/schemas/envelope")
public Product getProduct(){...}
#XmlElement(name="Instance", namespace = "http://www.mypage.com/schemas/envelope")
public Instance getInstance(){...}
}
public class Product {
#XmlElement(name="number", namespace = "http://www.mypage.com/schemas/pdi")
public int getNumber(){...}
}
public class Instance {
#XmlElement(name="serial", namespace = "http://www.mypage.com/schemas/ib")
public String getSerial(){...}
}