empo
empo

Reputation: 1163

ASP.NET VB.NET how do i modify HTML at runtime

Can anyone tell me how to modify HTML at runtime please?

A user has pasted a table from Word into a text editor control (FCKEditor)

The editor control automatically converts to HTML however I want to change the HTML before saving to database.

So, I want to make this

<table width="600" height=100>

into this

<table>

before saving string to the database.

Have tried using XmlDocument but LoadXml method doesn't like

&nbsp;

Any ideas?

Upvotes: 0

Views: 840

Answers (2)

Chris Haas
Chris Haas

Reputation: 55427

Alright, I'm going to get bashed by the agility pack people here, but if you've got a known pattern that you're looking to target its okay to use RegEx.

'Source Text
Dim text = "<table width=""600"" " & vbNewLine & "height=100>" & vbNewLine & "<td>hello</td>" & vbNewLine & "</table>"
'Replace all table tags just empty table tags
text = System.Text.RegularExpressions.Regex.Replace(text, "<table.*?>", "<table>", System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.Singleline)

Upvotes: 2

Keltex
Keltex

Reputation: 26426

Use the HTML Agility Pack (free / open source) to load the HTML into a DOM. Then you can manipulate it there.

Upvotes: 1

Related Questions