• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Automatic (or semi-automatic) alternative to cut and paste WANTED, please

New Here ,
Jul 09, 2021 Jul 09, 2021

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?

TOPICS
How to , Import and export , Scripting

Views

136

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2021 Aug 07, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

LATEST

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.

2021-08-07_14-29-45.png

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);
	}
}

2021-08-07_14-36-33.png

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines