java - Convert input String to File Object -
i want convert input string nothing xml java object. using jaxb same. problem calling application going receive xml in form of string. jaxbunmarshaller.unmarshal(inputxml);
expects file object in input. there way can convert input string file object without manually writing incoming content disk.
following method snippet
public void xmltoobject(string inputxml){ try{ jaxbcontext jaxbcontext = jaxbcontext.newinstance(lineitemsbeanlist.class); unmarshaller jaxbunmarshaller = jaxbcontext.createunmarshaller(); lineitemsbeanlist objreq= (lineitemsbeanlist) jaxbunmarshaller.unmarshal(inputxml); printlineitems(objreq.getlineitemsbean()); nba.processlineitems(objreq.getlineitemsbean()); nba.printfinalsetofrules(); } catch(exception e){ system.out.println(e); } }
you don't need make file object solve problem.
taken docs jaxb unmarshaller:
unmarshalling stringbuffer using javax.xml.transform.stream.streamsource:
jaxbcontext jc = jaxbcontext.newinstance( "com.acme.foo" ); unmarshaller u = jc.createunmarshaller(); stringbuffer xmlstr = new stringbuffer( "<?xml version="1.0"?>..." ); object o = u.unmarshal( new streamsource( new stringreader( xmlstr.tostring() ) ) );
in case can use similar method unmarshalling string:
lineitemsbeanlist objreq = (lineitemsbeanlist) jaxbunmarshaller.unmarshal( new streamsource(new stringreader(inputxml)));
Comments
Post a Comment