Monday 30 January 2012

Removing White Spaces (New Lines) in the XML Document


Removing XmlDocument white space c#

I've recently been working on matching certain API calls with XML data pulled from an XML file for testing purposes. I noticed there was a large amount of white space left in the XML when pulled from the resourced XML file; which is something I didn't want.
I thought setting the XmlDocument.PreserveWhitespace property to false would remove this for me, but it just seems to remove the preceding and trailing white space; making it similar to the string.Trim()method. I needed to use something akin to string.Replace() (this replaces a specific substring with another substring), but more powerful. Here comes the Regex.Replace function to the rescue, which is a bit like string.Replace() on steroids! Regex.Replace() allows replacement of text using regular expressions, something which can make make complex replacements a piece of cake.
Here is the code to replace white space in XML or any XML dialect(such as HTML - or XHTML):

  1. / Remove inner Xml whitespace  
  2. Regex regex = new Regex(@">\s*<");  
  3. string cleanedXml = regex.Replace(dirtyXml, "><"); 

Tuesday 3 January 2012

Convert C# to VB

DataSet Designer (Editor) MissingDataSet Designer (Editor) Missing


I had a strange problem with his VisualStudio 2008. All the sudden he couldn’t view the DataSet designer in any applications. When the DataSet file was clicked all that it showed was the XML file, no sign of the Designer.
We don’t know what happened but as I tried to figure out the problem I found that there’s very few information about this problem on the Internet, so I decide to blog about it so that it might help someone in distress.
If you’re having this problem you might first try to right click the DataSet file and then select the Open With… option. A list of editors will show, if you don’t see the DataSet Editor then you you have the same problem we did.

I have found a few posts about it, here are the solutions proposed:
  • Run the following command in the VisualStudio prompt: devenv /resetsettings
  • Run the following command in the VisualStudio prompt: devenv /setup
  • With Visual Studio setup disc select the Repair option.
  • Re-install Visual Studio.
All these are valid solutions and I found people on the web who claimed that this helped them but for my unfortunate teammate it didn’t help. The only thing that did it for us was:
  1. Remove VisualStudio
  2. Delete any folder left from VS installation
  3. Install VisualStudio
Finally, problem solved! I know this is not an optimal solution, far from it but at the end of the day it works. Nothing else did. I hope this post helps some else.

Adding Templates To Visual Studio 2008


Close all instance of Visual Studio.

Open visual studio command prompt and type, devenv /installvstemplates.Press Enter.

(to open command prompt  :

Start\Programs\Microsoft Visual Studio\Visual Studio Tools\Visual Studio 2008 Command Prompt)
when the process is complete ,open visual studio.

You will get all missing templates under Visual Studio installed templates.