Enonic version: 6.4.2
OS: Mac and Linux
I can use JSON.parse(), but there seems to be no XML.parse()?
Does Enonic have it’s own XML parser, and is it available for use in a part controller, or do I have to get my own xml parser?
Do you have any recommendation for a XML parser available as npm package?
JSON.parse() is part of the
EcmaScript 5 standard -
For parsing Java, I’m sure you can use whatever Enonic uses by
invoking Java. After some digging, I found Enonic’s XML-parsing classes here:
An alternative can be to include your XML parser of choice in the Gradle build script and include it the same way.
A third alternative, in pure JS, is to use a webjar with a JS lib for parsing XML. Find whatever you need on
webjars.org, and include it in the Gradle build script of your site. XML2JS looked good, but I’ve never used an XML parsing lib for JS, so I can’t really speak to it. This question on SO has some good suggestions as well.
March 30, 2016, 9:43pm
Are you using an HTTP service in a controller to get an external XML source?
Yes I’m fetching external content
Note: Can’t use xml2json right now at least
04:06PM - 06 Apr 16 UTC
01:23PM - 09 May 16 UTC
Old versions of "nan" seems to be gone (from webjars at least).
Please upgrade node-expat to get newer existing version:
Here's the error...
There are build issues for xml2js and xml4js too. Webjar dependancy tree seems broken to me.
I’m not a java programmer, so if this is completely stupid you know why
var bean = __.newBean('com.enonic.xp.xml.parser');
var source = __.toNativeObject(bean.source(file));
var data = __.toNativeObject(bean.parse);
c.e.x.p.i.e.ExceptionRendererImpl - java.lang.ClassNotFoundException: com.enonic.xp.xml.parser not found by com.enonic.xp.core.api 
April 6, 2016, 10:10pm
You are trying to invoke something that doesnt exist in the api, com.enonic.xp.xml.parser is just a package, and the classes in there will probably not help you.
I’ve created a small test-project that should give you a pointer on how to setup a java based xml-parser:
Its not tested or optimized in any way, so beware
./gradlew clean deploy
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ‘:compileJava’.
Could not find tools.jar
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Total time: 7.659 secs
Still getting Could not find tools.jar
With this I can compile your github project at least:
Had forgotten org.json in build.gradle
Including those few java files increased the build time with 45 seconds on my machine.
Going from 15 sedonds to a full minute is terrible.
I’ve tried many combinations of
./gradlew --daemon -t deploy without it reducing build time, on the first, or following builds.
Why does it even rebuild the java files. I haven’t touched them…
Or perhaps we could we make a webjar or something out of the xmlparser java code.
April 13, 2016, 1:49pm
Clean build of the xmlParser app takes 4 seconds on my computer, and the resulting jar is 1.8MB.