I am writing an HTML parser in Flex (AS3) and I need to remove some HTML tags which are not necessary Are there. / P>
For example, I want to remove the divs from this code:
& lt; Div & gt; & Lt; Div & gt; & Lt; Div & gt; & Lt; Div & gt; & Lt; Div & gt; & Lt; Div & gt; & Lt; Div & gt; & Lt; P style = "padding-left: 18px; padding-right: 20px; text-align: center;" & Gt; & Lt; Period & gt; & Lt; / Span & gt; & Lt; Span style = "font-size: 48px; color: # 666666; font-style: normal; font-weight: bold; text-decoration: none; font-family: aerial;" & Gt; 20% OFF. & Lt; / Span & gt; & Lt; Period & gt; & Lt; / Span & gt; & Lt; Span style = "font-size: 48px; color: # 666666; font-style: normal; font-weight: normal; text-decoration: none; font-family: aerial;" & Gt; Do it now! & Lt; / Span & gt; & Lt; Period & gt; & Lt; / Span & gt; & Lt; / P & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;
and finish with something like this:
& lt; Div & gt; & Lt; P style = "padding-left: 18px; padding-right: 20px; text-align: center;" & Gt; & Lt; Period & gt; & Lt; / Span & gt; & Lt; Span style = "font-size: 48px; color: # 666666; font-style: normal; font-weight: bold; text-decoration: none; font-family: aerial;" & Gt; 20% OFF. & Lt; / Span & gt; & Lt; Period & gt; & Lt; / Span & gt; & Lt; Span style = "font-size: 48px; color: # 666666; font-style: normal; font-weight: normal; text-decoration: none; font-family: aerial;" & Gt; Do it now! & Lt; / Span & gt; & Lt; Period & gt; & Lt; / Span & gt; & Lt; / P & gt; & Lt; / Div & gt;
My question is, how can I write a regular expression to remove these unwanted divas? Is there a better way to do this?
Thanks in advance.
Assume that your targeted HTML is actually valid XML, you can pull out non-partition bits You can use a recursive function for.
Non-static function grab (xml: XML): XMLList {var out: XMLList = new XMLList (); Var children: XMLList = xml.children (); For each (different child: XML in children) {if (child.name ()) and children. Name () == "Divi") {Various Grandfathers: XMLList = HorizontalNonDiva Contents (Toddler); Each (var Grandkids: XML in the Grand Cad) {out + = grandKid; }} And {outside + = child; }} Return; }
Comments
Post a Comment