does anyone have any good examples of using Javascript to read various xml (they will be different for each job) and create a document with the information in it?
Trying to create an on the fly ticket for each job that comes in to our flow.
Using xml variable files to write to a ticket type of document
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Using xml variable files to write to a ticket type of document
There are 2 methods for reading XML - XPath and DOM
XPath example using a XML dataset
var pdfInfo = job.getDataset("Pdf");
if (pdfInfo != null) {
var theNumberofColors = pdfInfo.evalToNumber( "count(/pdfattrs/colors/*)", null);
var theFirstColorValue = pdfInfo.evalToString( "/pdfattrs/colors/color[0]/@base", null );
}
DOM example using an XML file
var theXML = new Document("sample.xml");
var docElem = theXML.getDocumentElement();
var nodeList = theXML.getDocumentElement().getChildNodes();
for (var i=0; i < nodeList.length; i++) {
var theNode = nodeList.getItem(i);
if (theNode.getBaseName() == "resources") {
var id = theNode.getAttributeValue( "id" );
}
}
You don't mention what type of "ticket" you want to write.
XPath example using a XML dataset
var pdfInfo = job.getDataset("Pdf");
if (pdfInfo != null) {
var theNumberofColors = pdfInfo.evalToNumber( "count(/pdfattrs/colors/*)", null);
var theFirstColorValue = pdfInfo.evalToString( "/pdfattrs/colors/color[0]/@base", null );
}
DOM example using an XML file
var theXML = new Document("sample.xml");
var docElem = theXML.getDocumentElement();
var nodeList = theXML.getDocumentElement().getChildNodes();
for (var i=0; i < nodeList.length; i++) {
var theNode = nodeList.getItem(i);
if (theNode.getBaseName() == "resources") {
var id = theNode.getAttributeValue( "id" );
}
}
You don't mention what type of "ticket" you want to write.