This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SPML JAXB with Custom Child Element of <data> tag  RSS feed

J Ha
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am looking for solution to add custom child element to <data> tag using jaxb generated source code.
I am working with 2 xsd: spml2core xsd i attached to this post and second xsd for the child element under
<data> tag of spml payload. I was able to marshal the following spml2 payload using generated
java class using xjc and jaxb api, but I can't figure out how to remove the ns2 prefix on the child element of
data tag.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addRequest targetID="TargetID" xmlns:ns2="schema location for child element acProvisioningRequest" xmlns="urnasis:names:tc:SPML:2:0">
<ns2:acProvisioningRequest environment="DEV" acRequestID="1000000">
<ns2:customer action="N" id="TEST_CLIENT_PROFILE_ID">
<ns2:user action="A" lastName="Doe" firstName="John" id="USER_ACCESS_ID"/>

the resulting output i am looking for after marshalling xml out of jaxb object is this

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addRequest targetID="TargetID" xmlns="urnasis:names:tc:SPML:2:0">
<acProvisioningRequest environment="DEV" acRequestID="1000000" xmlns="schema location for child element acProvisioningRequest">
<customer action="N" id="TEST_CLIENT_PROFILE_ID">
<user action="A" lastName="Doe" firstName="John" id="USER_ACCESS_ID"/>

I'll be looking for solution on my end too, but any and all help is much appreciated. I was looking through information
concerning jaxb bindings, but I haven't had much luck.

I used to following java code snippet to generated the above output.

code used to generated this.jaxbRequestData jaxb object which is the root element of schema under <data> tag

ObjectFactory spml2Factory = new ObjectFactory(); // object factory for spml2 package
....spmldata.ObjectFactory spmldataFactory = new .....spmldata.ObjectFactory(); // object factory on child element of <data> tag package

ExtensibleType data = spml2Factory.createExtensibleType();
AddRequestType addRequestType = spml2Factory.createAddRequestType();



StringWriter resultWriter = new StringWriter();
JAXBContext jc = JAXBContext.newInstance("....jaxb.spmlrequest:.....jaxb.spmldata"); // locations of both java package
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
resultWriter = new StringWriter();

m.marshal( spml2Factory.createAddRequest(addRequestType), resultWriter );

Thanks in advance for your help!

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!