Tuesday, March 5, 2013

Client Side Xml from IE Meets Server Side Xml C#

In Internet Explorer (8), when adding xml with namespaces to the DOM… it adds a partial xml declaration “<?xml:namespace prefix…”. 
In IE this is not a problem, but in the asp.net webApi I’m using XElement.Parse(xml) to do some clean up like remove jquery id’s and some css that gets added from AngularJs.
XElement.Parse(xml) blows up! So before parse, I’m removing the node with the following code. I’ve written a few tests, seems to work. I’d like to say I’ll post my tests later, but I doubt that will happen.

public string FixIENamespace(string contentStream)
      {
          const string pattern = @"<\?xml:namespace prefix =.* />";
          const string replacement = "";
          var rgx = new Regex(pattern);
          var result = rgx.Replace(contentStream, replacement);
          return result.ToString(CultureInfo.InvariantCulture);
      }

I have not had this problem with Chrome.

No comments:

Post a Comment