I've generated a whole bunch of Java classes from a ( to me at least ) rather complex XML schema. I am having difficulty building up a content tree and marshalling it. I have read more tutorials than I can count over the past few days but all of the examples represent very trivial applications.
I used xjc to compile to schema a local file: “NetConnect.xsd”. It created the package structure com.experian.netconnect to hold the NetConnect folder of classes and ( without me manually doing anything ) also created created a webdelivery folder full of classes.
This is whaty my marshalled xml output SHOULD look like:
…...<?xml version=”1.0” encoding=”UTF-8”?> <NetConnectRequest xmlns=”http:/www.experian.com/NetConnect” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.experian.com/NetConnect NetConnect.xsd> <EAI> some stuff </EAI> <DBHost> stuff </DBHost> <ReferenceId> stuff </ReferenceId> <Request xmlns=”http://www.experian.com/WebDelivery” version =”1.0”> <Products> <AddressUpdate> <Subscriber> stuff </Subscriber> <PrimaryApplicant> <Name>
and so on and so forth for the primary applicants name and address, etc, same for secondary applicant.
My issue is that when marshalled to System.out the output looks like this:
<?xml version=”1.0” encoding=”UTF-8” standalone=”yes”?> <NetConnectRequest xmlns:n2=”http://www.experian.com/WebDelivery”> <EAI>23465</EAI> <DBHost>TEST</DBHost> <ReferenceId>237846</ReferrenceId> <ns2:Request/> <?NetConnectRequest>
so it appears to be ignoring everything inside the <Request xmlns=”http://www.experian.com/WebDelivery” version =”1.0”> tag
Here is my code ( Since I'm just trying here to work out the raw 'how it's done', I only have a few elements and nodes with the content set ):
public class Marshalling { public static void main(String[] args) throws JAXBException { com.experian.webdelivery.ObjectFactory objectFactory = new com.experian.webdelivery.ObjectFactory(); com.experian.netconnect.ObjectFactory netObjectFactory = new com.experian.netconnect.ObjectFactory(); RequestType requestType = objectFactory.createRequestType(); RequestType.Products products = new RequestType.Products(); AddressUpdateType addressUpdate = objectFactory.createAddressUpdateType(); NetConnectRequest request = netObjectFactory.createNetConnectRequest(); NameType name = objectFactory.createNameType(); products.setAddressUpdate(addressUpdate); request.setRequest(requestType); request.setEAI("23465"); request.setDBHost("TEST"); request.setReferenceId("237846"); SubscriberType subscriber = objectFactory.createSubscriberType(); addressUpdate.setSubscriber(subscriber); subscriber.setPreamble("TEST"); subscriber.setSubCode("23874654"); PrimaryApplicantWithPINType primaryApplicant = objectFactory.createPrimaryApplicantWithPINType(); addressUpdate.setPrimaryApplicant(primaryApplicant); name.setFirst("Marc"); name.setSurname("Holman"); name.setMiddle("D."); primaryApplicant.setName(name); addressUpdate.setSubscriber(subscriber); JAXBContext context = JAXBContext.newInstance("com.experian.netconnect:com.experian.webdelivery"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty("jaxb.formatted.output", true); SchemaFactory schemaFactory = SchemaFactory.newInstance(("http://www.w3.org/2001/XMLSchema")); marshaller.marshal(request, System.out); } }
I'd really appreciate it someone could explain to me what's gone wrong here? Am I building the content tree wrong? I'm truly stumped.