Home › Forums › General XMetaL Discussion › Scripting: Something like getElementsByTagName, for specific attribute & value? › Reply To: Scripting: Something like getElementsByTagName, for specific attribute & value?
Reply to: Scripting: Something like getElementsByTagName, for specific attribute & value?
March 10, 2009 at 9:11 pmThe API getNodesByXPath will allow you to return a list of element nodes that have specific attributes set. Here is an example that tells you how many
elements in your document have an id attribute value:
[code]
// XMetaL Script Language JSCRIPT:
var parasWithId = ActiveDocument.getNodesByXPath(“//p[@id]”);
Application.Alert(parasWithId.length);[/code]
This API returns a DOMNodeList of DOMElement objects. For more information refer to the XMetaL Developer Programmers Guide.