🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #2230

Re: Changing Values in XML tags

#2230
From: Gary_Vidal
Date: Wed, 07 Jan 2009 01:19
33 lines
1764 bytes
like to use a little function like this that allows for tree traversals on Indesign DOM, the only thing you would have to do is write a javascript line like so. Overly complex but this function has saved my alot of time recreating the wheel.

//Set invocation
invokeFunctionOnNode(parentNode,function(node)
{
  if(node.markupTag.name == "ART_PRICE")
  {
     node.contents = "0.0";
  }
});

/*
=================================================
function recurses each node in the DOM and calls the anonymous method
function should have a single value of the node
=================================================
* / function invokeFunctionOnNode(parentNode, func) {
	var pNode = parentNode;	
	//Call on Parent Node	
	func(pNode);
	var elementCount = 0;
	try{
		elementCount = pNode.xmlElements.length;
	}catch(ex){}
	if (elementCount > 0) {
		var ctr = 0;
		for (var elem = 0 ; elem < elementCount; elem++) { 			var currentNode = pNode.xmlElements.item(elem); 			func(currentNode); 			try { 				if (currentNode.xmlElements.length > 0) {
					invokeFunctionOnNode(currentNode, func) ;
				}	
			} catch(ex) {}
		}		
	}
}
Technical Details
Message-ID: <59b7651b.12@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!news2!news.glorb.com!newshub.sdsu.edu!webcrossing
References: <59b7651b.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,d78f6b73256f6f00
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Gary_Vidal@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!news2!news.glorb.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: Changing Values in XML tags
Message-ID: <59b7651b.12@webcrossing.la2eafNXanI>
Date: Tue, 6 Jan 2009 17:19:25 -0800
References: <59b7651b.-1@webcrossing.la2eafNXanI>
Lines: 41
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit