Site logo

XML

evaluateXPathExpression vs XML-rules: which is better?

Creating a parent xml element from a selection in the Structure Pane.

var myDoc = app.activeDocument;
var mySel = app.selection;
 
var newParent = myDoc.xmlElements[0].xmlElements.add({markupTag:"c_bullet_list"}).move(LocationOptions.before, mySel[0]);
 
var i = mySel.length;
while (i--) {
	mySel[i].move(LocationOptions.AT_BEGINNING, newParent);   
}

Locate and run the glue code.jsx file

var glueFile = new File(app.filePath + "/Scripts/XML Rules/glue code.jsx");
if (glueFile.exists) app.doScript(glueFile, ScriptLanguage.JAVASCRIPT)
	else ErrorExit("\"glue code.jsx\" should be located in the \"Scripts > XML Rules\" folder for the script to work.", true);

Setting a namespace attribute

var x = ;
var ns = new Namespace ("xlink", "http://www.someuri.com/1.0");
x.addNamespace (ns);
x["@xlink:url"] = "tutu.jpg";
alert(x.toXMLString());

The source is here

How to check if an XML element has been placed

if (xmlEl.xmlContent.parent.constructor.name != "XmlStory") {
	// not-placed
}
else {
	// placed
}

Load xml from Web into an InDesign document

Do you need to generate HTML table rows from XML in InDesign?

Process XML Data for InDesign (a script example that uses XML files as a sort of database for creating InDesign files from templates)

Removing not placed xml elements

Reading information from an XML file in InDesign