EvalTo functions with JDF

Post Reply
cstevens
Member
Posts: 40
Joined: Tue Feb 12, 2013 8:42 pm

EvalTo functions with JDF

Post by cstevens »

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.
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

EvalTo functions with JDF

Post by freddyp »

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
cstevens
Member
Posts: 40
Joined: Tue Feb 12, 2013 8:42 pm

EvalTo functions with JDF

Post by cstevens »

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.");
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

EvalTo functions with JDF

Post by gabrielp »

cstevens wrote: Just so folks can see here's the working code:


Thanks for sharing your solution!
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Post Reply