如何将内容添加到xml元素中?

时间:2015-07-01 11:45:41

标签: xml extendscript adobe-indesign

我需要在sqrt的xml元素中插入一个单词m:msqrt(没有标签的纯文本),如下所示:

enter image description here

我试过了:

var path = (app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');
//path of active document(sample.indd)

var xmlPath = (app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/')+"/with_aid2.xml";

xmlFile = File (xmlPath);

if(xmlFile.exists){
    xmlFile.open();
    var myString = xmlFile.read();
    xmlFile.close();
    myXml = new XML ();
    myXml = XML(myString);
    var msqrtCount = myXml.xpath("//m:msqrt");

}else{alert(xmlPath+" doesn't exist!");}

for(var i=0;i<msqrtCount.length();i++){  
    var added =    msqrtCount[i];
    added.contents="sqrt";       
}

我收到错误说无效的内容属性。

0 个答案:

没有答案