Hello,
My first time here so...: There is a SOAP service which I'd like to model 
and output in various formats,(HTML, PDF, etc). Since I'm fairly new to 
NodeJS I've been testing techniques to build the application, but have come 
to an impasse in how to proceed. The main issue is in transforming the SOAP 
response and whether I should do it client-side or server-side. Here is 
what I've found so far

Using node-java <https://github.com/joeferner/node-java> and Saxon-HE 
<http://saxon.sourceforge.net/> server-side, (snippet):

const https = require('https')
const java = require('java')
const fs = require('fs')

java.classpath.push('C:\\Saxon-HE\\saxon9he.jar')
const Processor = java.import('net.sf.saxon.s9api.Processor')
const StreamSource = java.import('javax.xml.transform.stream.StreamSource')
const File = java.import('java.io.File')
const proc = new Processor(false)
const comp = proc.newXsltCompilerSync()
const exec = comp.compileSync(new StreamSource(new File('identity.xsl')))
const srce = proc.newDocumentBuilderSync().buildSync(new StreamSource(new 
File('soap-response.xml')))
const outp = proc.newSerializerSync()
outp.setOutputFile(new File('output.xml'))
trans = exec.loadSync()
trans.setInitialContextNodeSync(srce)
trans.setDestinationSync(outp)
trans.transformSync()

However, this seems *slow* as heck... so if I need to transform multiple 
documents for many users this could be problematic. Next, I tried pairing 
jsdom <https://github.com/jsdom/jsdom> and Saxon-CE 
<https://www.saxonica.com/ce/user-doc/1.1/html/about/> in the hope that I 
could transform the live page and write it back to the file system (REPL 
output is edited)


var sandbox = {console : console,require : require}

vm.runInNewContext("const fs = require('fs');const jsdom = 
require('jsdom');const {JSDOM} = jsdom;",sandbox,"myfile.vm")

vm.runInNewContext("JSDOM.fromURL('http://localhost/joshua.html',{pretendToBeVisual
 
: true,runScripts : 'dangerously',resources : 
'usable'}).then((dom)=>{this.window = dom.window;this.document = 
dom.window.document;this.dom = 
dom;console.log(dom.serialize());});",sandbox,"myfile.vm")

Error: Not implemented: navigation (except hash changes)
    at module.exports 
(C:\Users\user\AppData\Roaming\npm\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)


Apparently, jsdom's navigation is limited to hashes, so the magic little 
HTML file needed by Saxon-CE isn't cached and the process is halted. I can, 
however,  update the head element of the webpage with the transformation 
script and then write it back to the file system:


vm.runInNewContext("JSDOM.fromURL('http://localhost/joshua.html',{pretendToBeVisual
 
: true}).then((dom)=>{this.window = dom.window;this.document = 
dom.window.document;this.dom = 
dom;console.log(dom.serialize());});",sandbox,"myfile.vm")

vm.runInNewContext("var script = 
document.createElement('script');script.type = 
'text/javascript';script.text = 'onSaxonLoad = function(){proc = 
Saxon.run({stylesheet : \"mydemo.xsl\",source : \"mydemo.xml\",logLevel : 
\"SEVERE\"})}';document.getElementsByTagName(\"head\")[0].appendChild(script);",sandbox,"myfile.vm")

vm.runInNewContext("console.log(dom.serialize());data = 
dom.serialize();fs.writeFile('./../../wamp64/www/joshua.html',data,(err)=>{if 
(err) throw err;});",sandbox,"myfile.vm")



The main issue is I need to pass the outputted XML from XSL transformation 
to another as well as produce different output formats, and the other Node 
libraries I have seen are either dead or bleeding edge, emphasis on the 
exsanguination... Any advice on how to do this cogently and securely would 
be greatly appreciated. Thanks!!

N.




-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/f58ab6ac-e321-4524-aa06-321efbdb42fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to