Home › Forums › General XMetaL Discussion › Insert DITA XML fragment into the DOM › Reply To: Insert DITA XML fragment into the DOM
Reply to: Insert DITA XML fragment into the DOM
October 22, 2013 at 9:42 pmOK, I've just programmatically inserted a table and I have no trouble calling getNodesByXPath inside the same macro and in a second macro. It tells me my table is there, it also doesn't matter if it is currently rendered as a table or not.
I'm testing with the current release of XMetaL Author Enterprise which is 8.0.1.041. I don't think we've worked much on this area of the product recently, but perhaps your specific release has some limitations.
Here are two of the simplest possible tests I can think of.
For a DITA document this one will make the document invalid and the table cannot even be rendered as one due to all the missing bits:
[code=test 1]// XMetaL Script Language JSCRIPT:
if(Selection.FindInsertLocation(“table”)) {
Selection.InsertElement(“table”);
var tables = ActiveDocument.getNodesByXPath(“//table”);
Application.Alert(“# of tables: ” + tables.length);
}
else {
Application.Alert(“Unable to insert a table element.”);
}[/code]
This one inserts an entire valid table from a string:
[code=test 2]// XMetaL Script Language JSCRIPT:
if(Selection.FindInsertLocation(“table”)) {
Selection.PasteStringWithInterpret('
');
var tables = ActiveDocument.getNodesByXPath(“//table”);
Application.Alert(“# of tables: ” + tables.length);
}
else {
Application.Alert(“Unable to insert a table element.”);
}[/code]
In both cases the Alert should say that there is at least one table after insertion (more if the document already contains some).