-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCleanXMLStructure.jsx
30 lines (29 loc) · 1.01 KB
/
CleanXMLStructure.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*Script that will remove all the text XML Nodes which are not placed on the document
Pre Requisite:- The script needs an open document
Warning :- No elaborate error checking
Author:- Manan Joshi
Github Repo :- https://github.com/Manan-Joshi/InDesign-Scripts.git
*/
function cleanXMLStructure(){
var doc = app.documents[0]
$.writeln("PageItems before " + doc.allPageItems.length)
var root = doc.associatedXMLElement.xmlElements[0]
var dl = []
for(var i = 0; i < root.xmlElements.length; i++){
var el = root.xmlElements[i]
var pe = el.xmlContent
var isPlaced = null
if(pe instanceof Text){
isPlaced = pe.parentStory.textContainers.length
}else if(pe instanceof Story){
isPlaced = pe.textContainers.length
}
if(isPlaced != null && isPlaced === 0){
dl.push(el.getElements()[0])
}
}
for(var i = 0; i < dl.length; i++){
dl[i].remove()
}
$.writeln("PageItems after " + doc.allPageItems.length)
}