Answered
how to change position of new xml element as immediate sibling to current xml Element using JSscript

I am trying to change position of nav-pointer tag as immediate sibling of term element as like shown below,


I am trying to change position of nav-pointer tag as immediate sibling of term element as like shown below,

Try this code:
moveTerm()
function moveTerm(){
var myDoc = app.documents[0];
var xPath = ['//term'];
var root = myDoc.xmlElements[0];
var node = null;
try{
var proc = app.xmlRuleProcessors.add(xPath);
var match = proc.startProcessingRuleSet(root);
while (match != undefined){
node = match.element;
match = proc.findNextMatch();
if(node != null && node != undefined){
if(node.parent.xmlElements.length > node.index+1){
var nextSibling = null;
for(var i = node.index+1; i < node.parent.xmlElements.length; i++){
if(node.parent.xmlElements[i].markupTag.name == "nan-pointer"){
nextSibling = node.parent.xmlElements[i];
break;
}
}
if(nextSibling != null){
nextSibling.move(LocationOptions.after, node);
}
}
}
}
}
catch(ex){}
finally{
proc.endProcessingRuleSet();
proc.remove();
}
}
Best
Sunil
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.