java - Is there any alternative to XSLT -
in application, converting xml java object using 2 steps. in 1st step doing xml xml transformation using xslt. in second step, binding xml java object using jibx api.
step1: documentbuilder builder = domfactory.newdocumentbuilder(); document doc = builder.parse(inboundmessagedata.getdatastream()); inputstream instream = xslttransformationutil.transform(doc, xsltfilename); step2: runtimedocument document = xmlbindingservice.unmarshall(instream, runtimedocument.class); is possible that, these 2 steps can achieved in single step or have api can use this. in advance.
if java (domain) model not align input document, highly recommend use xslt done you. however, possible in 1 step , more efficient using standard java. see jaxbresult javadoc.
example code (using java se 6+):
/** * read file `./29238845.xml`, transform our internal canonical productxml , * bind to java `product` domain instance. */ @test public void testunmarshal() throws transformerexception, jaxbexception { final transformerfactory factory = transformerfactory.newinstance(); final transformer t = factory.newtransformer( new streamsource(new file("./product.xsl"))); final jaxbcontext context = jaxbcontext.newinstance(product.class); final jaxbresult result = new jaxbresult(context); t.transform(new streamsource(new file("./29238845.xml")), result); final product p = (product)result.getresult(); assertequals("n3v96ea", p.getmpn()); }
Comments
Post a Comment