Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to strip out XML

Status
Not open for further replies.

kifaro

Programmer
Oct 4, 2002
54
US
I need to pull all XML tags out of a string I have. Anyone have any clue what regex I could use??

Thanks,
Aaron

So far I have:



Function stripXML(strHTML)
'Strips the HTML tags from strHTML

Dim objRegExp, strOutput
Set objRegExp = New Regexp

objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = &quot;s/<[^<>&quot;&quot;]*(&quot;&quot;[^&quot;&quot;]*&quot;&quot;*[^<>&quot;&quot;]*)*>//&quot;

'Replace all HTML tag matches with the empty string
strOutput = objRegExp.Replace(strHTML, &quot;&quot;)

'Replace all < and > with &amp;lt; and &amp;gt;
'strOutput = Replace(strOutput, &quot;<&quot;, &quot;&amp;lt;&quot;)
'strOutput = Replace(strOutput, &quot;>&quot;, &quot;&amp;gt;&quot;)

stripXML = strOutput 'Return the value of strOutput

Set objRegExp = Nothing
End Function
 
I've used a regexp to pull out all tags (HTML XML CFM)
I beleive it was:

&quot;<.*?>(.*?)&quot;

That would assume that the first thing you would find is a tag... If you switch the <> and the () you can gather stuff before the first tag... I usually do it the way it is written and force a dummy tag into my text &quot;<hi>&quot; before the first line, then I loop through the search results and only output the submatch... thus removing all tags. Or the Match if you want to gather all tags.
have fun.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top