Hello,
I'm trying to parse some data from a JDF ticket using the EvalToNodes() function, but don't seem to be having any luck.
Something like this:
var inputDIR = new Dir(job.getPath());
var jdfFileList = inputDIR.entryList("*.jdf", Dir.Files, Dir.Time);
var baseJDF = new Document(job.getPath() + "" + jdfFileList[0]);
var baseJDFdocElem = baseJDF.getDocumentElement();
var baseResourcePool = baseJDFdocElem.evalToNode("./jdf:ResourcePool", null);
I don't have issues using these functions on standard XML files, only with JDF. I've also tried with and without the "jdf:" prefix and no luck there. Do I need to do something with a prefix map to get this to work?
I can work around this using GetChildNodes() and parse the nodes for the base name that I need, but it would be a lot cleaner if I could use the EvalTo functions.
EvalTo functions with JDF
EvalTo functions with JDF
Yes, it is better to work with a prefix map. You can easily get that with:
var nsMap = baseJDF.createDefaultMap();
and you use nsMap as the second parameter in evalToNode.
Another thing, jdf: is used as the name of the default namespace for JDF files. For "normal" XML files the default namespace is referred to as dn:. As you are reading the JDF file as a normal XML file you should use dn:.
Freddy
var nsMap = baseJDF.createDefaultMap();
and you use nsMap as the second parameter in evalToNode.
Another thing, jdf: is used as the name of the default namespace for JDF files. For "normal" XML files the default namespace is referred to as dn:. As you are reading the JDF file as a normal XML file you should use dn:.
Freddy
EvalTo functions with JDF
Thanks so much Freddy, I've been struggling with that one for months now.
Just so folks can see here's the working code:
var baseJDF = new Document(job.getPath() + slash + jdfFileList[0]);
var nsMap = baseJDF.createDefaultMap();
var baseJDFdocElem = baseJDF.getDocumentElement();
var baseRunList = baseJDFdocElem.evalToNodes("./dn:ResourcePool/dn:RunList", nsMap);
s.log(1, "Found " + baseRunList.length + " RunList elements in base JDF ticket.");
Just so folks can see here's the working code:
var baseJDF = new Document(job.getPath() + slash + jdfFileList[0]);
var nsMap = baseJDF.createDefaultMap();
var baseJDFdocElem = baseJDF.getDocumentElement();
var baseRunList = baseJDFdocElem.evalToNodes("./dn:ResourcePool/dn:RunList", nsMap);
s.log(1, "Found " + baseRunList.length + " RunList elements in base JDF ticket.");
EvalTo functions with JDF
cstevens wrote: Just so folks can see here's the working code:
Thanks for sharing your solution!
Thanks for sharing your solution!
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix