问题
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