您可以通过选择节点来接近。例如,选择第 3 层的所有元素,并在您将使用的所有层上扩展所有元素的过程中
app.select(
app.activeDocument.xmlElements.item(0) // the root element
.xmlElements.everyItem() // repeat this line for each nesting level
.xmlElements.everyItem() // and so forth
.getElements() // provide an array with the actual selectable items
);
重复指示线以获得更深层次。使用以下代码段,您还可以选择那些没有子元素的 XML 属性:
.xmlAttributes.everyItem()
最后取消选择以清理选择亮点。
app.select(null);
编辑:对于任意深度,您可以使用循环。在请求之前,它应该确保 XMLElement / XMLAttribute 集合中有元素。结果代码:
var items = app.activeDocument.xmlElements.everyItem();
while( items.xmlElements.length ) {
items = items.xmlElements.everyItem();
app.select(items.getElements());
if( items.xmlAttributes.length )
app.select(items.xmlAttributes.everyItem().getElements());
}
app.select(null);