Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Opinions please...

 

We have a web based application that is template driven. The template, HTML code, contains elements that we want to replace with code-generated HTML snippets (e.g. <FORM/> would be replaced with an HTML <form> Stuff here</form> element created by code).

 

We have two paths there. First we can load the template into a StringBuilder object and use the .Replace method to perform the string replacement. Second, we can load the template into an XmlDocument object and replace the element using the replaceChild method.

 

Both are fairly straightforward in nature, so the question is this: is one "better" than the other? Speed? Memory usage? This substitution is going to be used very heavily as each page of the site will be built using this code.

 

Any suggestions?

Thx

Tim

  • Administrators
Posted

Using an Xmldocument will make it easier to produce valid html / xml markup as it will take care of escaping non-valid character sequences etc.

 

Performance wise you would probably need to run a couple of comparisons to get a feel for which is going to give the best performance / feature tradeoff.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

How much flexibility do you need?

 

Is XSL-T an option. IME xsl-t's are the fastest replacement option.

 

XmlDocument's are extremely thick objects though, and creating an XslNavigator uses even more memory.

 

If it really is as simple as replacing text, I would stick with StringBuilder. It's the easiest to maintain, uses the least memory and is fastest with small sets.

Posted

I'd say KIS and use StringBuilder if all you need is simple text replacement; however, if you need to produce standards complient output; the XmlDocument may be a good option.

 

I don't know if this would apply in your situation, but would an approach like this help you: http://haacked.com/archive/2006/11/29/Express_Yourself_With_Custom_Expression_Builders.aspx

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...