General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Scripting: Something like getElementsByTagName, for specific attribute & value?

  • russurquhart1

    Scripting: Something like getElementsByTagName, for specific attribute & value?

    Participants 0
    Replies 1
    Last Activity 13 years, 3 months ago

    Hi,

    I am currently using getElementsByTagName to get a DOMnodelist. Is there a way to filter this list further with something like a getElementsByAttribVal(strAttrname, strVal)? I am currently looping though the list i get, to determine which nodes are to be worked on, but was just wondering if anyone had a better command to do this?

    Thanks,

    Russ

    Reply

    Derek Read

    Reply to: Scripting: Something like getElementsByTagName, for specific attribute & value?

    The 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.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support