Copy link to clipboard
Copied
I create documents by importing XML-data.
The XML is imported into a Master Page - but I need some of the information on another Master Page, and hence the copy/paste operation.
The structure of the XML looks someting like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LABEL>
<LABELTEXT language="en-US" programId="123456789" studyId="x_PackType_x" labelPoolId="x_PackType_x" comparator="x">
<XML-TAG01>Label text 01.</XML-TAG01>
<XML-TAG02>Label text 02.</XML-TAG02>
<XML-TAG03>Label text 03.</XML-TAG03>
<XML-TAG04>Label text 04.</XML-TAG04>
<XML-TAG05>Label text 05.</XML-TAG05>
</LABELTEXT>
</LABEL>
The data that needs moving = 123456789 from programId="123456789"
I can change it to a xml-tag if required.
I have a placeholder for the data on the receiving page.
What are my options - scripting or otherwise - in automating this operation?
Copy link to clipboard
Copied
Hey - sounds like an interesting issue.
I'm not 100% sure on this or what you are looking to do - can you elaborate on your workflow?
Copy link to clipboard
Copied
It's not clear to me what exactly you're trying to achieve, but this can be done by the script.
The general approach could be like so:
I assume you have a number of LABELTEXT xml-elements in your document.
You can get all of them who have the programId attribute into the array and loop through each element doing something with attribute values:
main();
function main() {
var xmlElement, xmlAttribute, value,
doc = app.activeDocument,
rootXml = doc.xmlElements[0],
programIdArr = rootXml.evaluateXPathExpression("//LABELTEXT[@programId]");
for (var i = 0; i < programIdArr.length; i++) {
xmlElement = programIdArr[i];
xmlAttribute = xmlElement.xmlAttributes.item("programId");
value = xmlAttribute.value;
$.writeln("Do something with programId " + value);
}
}