Flex的字符串到HTML的解析与DOM字符串、Flex、DOM、HTML

2023-09-08 15:10:35 作者:爱恨纵横交错

我有一个字符串:

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

我要解析字符串。接下来,我通过对象,ID或类得到的innerHTML。

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

例如:

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

在PHP中类,这很容易。但我不能用Flex创建此版本。

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

感谢您的帮助......

Thanks for help...

推荐答案

将其转换为在AS3原生XML,然后使用E4X解析所需的信息:

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]);

更多关于E4X,这是一个很好的引物: http://www.senocular.com/flash/tutorials/as3withflashcs3/?page = 4

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

 
精彩推荐