ノードを選択することで近づくことができます。たとえば、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);