0

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?

2 Answers 2

2

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)
Sign up to request clarification or add additional context in comments.

1 Comment

I agree - regular expressions are the way to go here. Loading up a DOM in memory just to do a search and replace seems like overkill to me.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.