Parsing XML/XHTML in Actionscript

前端 未结 3 785
梦谈多话
梦谈多话 2021-01-24 06:48

Is there anything similar to getElementById in actionscript?

I\'m trying to make a prototype of a flash page wich gets it\'s data from a xhtml file. I want to have both

3条回答
  •  无人及你
    2021-01-24 07:37

    Since you said your input would be XHTML, you can do it with XPath:

    import mx.xpath.XPathAPI;
    
    var elementId:String = "flashdataTitle";
    var elementPath:String = "//h1[@id'" + elementId + "']";
    found_elements = XPathAPI.selectNodeList(xhtml.firstChild, elementPath);
    
    if (found_elements.length == 1) {
      trace(found_elements[0]);
    }
    

    The code example is inspired from here, where you also can find some mode detail on XPath and ActionScript.

    AS3 has it's own XPath Library, the general approach would be the same.

提交回复
热议问题