0

AS 3.0 / Flash

  1. I am consuming XML which I have no control over.
  2. the XML has HTML in it which i am styling and displaying in a HTML text field.
  3. I want to remove all the html except the links.

Strip all HTML tags except links is not working for me.

does any one have any tips? regEx?

the following removes tables. var reTable:RegExp = /<table\s+[^>]*>.*?<\/table>/s;

but now i realize i need to keep content that is the tables and I also need the links.

thanks!!!

cp

Community
  • 1
  • 1
Cole Peterson
  • 184
  • 2
  • 2
  • 12

2 Answers2

0

Probably shouldn't use regex to parse html, but if you don't care, something simple like this:

find /<table\s+[^>]*>.*?<\/table\s+>/
replace ""

  • var reTable:RegExp = /]*>.*?<\/table>/s; removed the tables and everything in it. now i realize I need some of the content inside the tables. i will keep it at it.
    – Cole Peterson Dec 15 '11 at 23:40
0

ActionScript has a pretty neat tool for handling XML: E4X. Rather than relying on RegEx, which I find often messes things up with XML, just modify the actual XML tree, and from within AS:

var xml : XML = <page>
                  <p>Other elements</p>
                  <table><tr><td>1</td></tr></table>
                  <p>won't</p>
                  <div>
                      <table><tr><td>2</td></tr></table>
                  </div>
                  <p>be</p>
                  <table><tr><td>3</td></tr></table>
                  <p>removed</p>
                  <table><tr><td>4</td></tr></table>
            </page>;

clearTables (xml);

trace (xml.toXMLString()); // will output everything but the tables

function removeTables (xml : XML ) : void {
    xml.replace( "table", "");
    for each (var child:XML in xml.elements("*")) clearTables(child);
}
weltraumpirat
  • 22,544
  • 5
  • 40
  • 54