Monday, May 25, 2009

Whitespace is not allowed at this location.

Am not a fan of Ado.net in XML and that is because its sometimes so consfusing and time consuming if you have get a work around for a problem of mulformed tags in the xml, well i might not be a fan but the previous programmer whom i inherited the project from was a fan of XML. well in a web application everything is xml based, database manupilation is done in xml, a lot of serialization and desirialization. it will take you more that ten lines of code , doing the looping to save data to SQL through a large dataset , but if you use straight ado.net object it will take you 5 or less lines and it depends on the parameters. now lets get to the point of this Blog.

i came across an error on an XMl that reads

XML comment contains invalid XML: Whitespace is not allowed at this location".

This is because in your Column fields that you pass to the Xml there is ampresant and in XML its a special character, now you need to turn it off. well in my case and your case its simple , you need to leave your code the way it and in your code where you pass the xml string, you must use the replace function in C# or Vb.net like this



Xml.Replace("&", "& amp;");

the "&" will turn it off and everything will be good again.


Thank you

Vuyiswa Maseko