Flex String to HTML for parse with DOM

纵饮孤独 提交于 2020-01-17 01:29:09

问题


I have a string:

private str:String = '
<!DOCTYPE html>
<html>
<body>
<div>TEST</div>
<span id="t1">T1 Content</span>
<span class="t2">T2 Content</span>
</body>
</html>';

I want to parse the string. Next, I get innerHTMl via Object, ID or Class.

E.g.:

Objects: Body, Div, Span
IDs: t1
Classes: t2

In PHP with the class, it's easy. But I could not create this build with Flex.

Thanks for help...


回答1:


Convert it to native XML in as3, then use e4x to parse the information required:

var xml:XML = XML(str);

//trace the content of any span with the id of "t1"
trace(xms..span.(attribute("id") == "t1"));

//trace the content of any span with the class t2
trace(xml..span.(attribute("class") == "t2"));

//trace the contents of the first div
trace(xml..div[0]);

For more on e4x, this is a good primer: http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=4



来源:https://stackoverflow.com/questions/12183788/flex-string-to-html-for-parse-with-dom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!