Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / XML

.Net - Use The Framework

2.33/5 (9 votes)
6 Apr 2010CPOL 1  
The following is far easier to understand and use than the Outlaw's tip (IMHO).text = Regex.Replace(text, screen_fadetimeout=[^']+, screen_fatetimeout=99);It has the following advantages:1. It is one line of code2. It is easier to read3. It is faster (note: XmlElement...
The following is far easier to understand and use than the Outlaw's tip (IMHO).

text = Regex.Replace(text, "screen_fadetimeout=\"[^\"\']+\"", "screen_fatetimeout="99");


It has the following advantages:
1. It is one line of code
2. It is easier to read
3. It is faster (note: XmlElement uses Regex in it's implementation) and further speed can be gained by using a compiled Regex instance.
4. No need to worry about null references (what if the desired element doesn't exist?)
5. It is light compared to XmlElement.Parse()
6. If you need to know if the item was found, you can use the MatchEvaluator overload and an anonymous delegate -- still one line of code.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)