Home > Enterprise >  Removing and  to get valid XML?
Removing and  to get valid XML?

Time:11-10

I have a WCF service (.NET C#) that sometimes returns for example 
 and  which is not correct XML.

I guess I could build a translator that are applied on each string field before sending response but it feels a bit sketchy, I do not know what to look for(more then the above) or what to translate it into. Maybe there is a existing solution for this?

CodePudding user response:

&#xD stands for a new line (the way i know). The behavoir is the same as Environment.NewLine. So you can replace it easily:

string text = yourString.ToString().Replace("&#xD", Environment.NewLine).

Dont know if this is what you're searchin for, but thats the only thing thats in my mind right now.

Hope it helps. :)

CodePudding user response:

These characters are allowed in XML 1.1 but not in XML 1.0. XML 1.1 has not been a great success and Microsoft has never supported it.

Does the XML declaration at the start of the file say version="1.1"?

A clean way to handle this would be to process the file using a parser that does support XML 1.1, converting it to XML 1.0 in the process. For example, you could do this with a simple Java SAX application, or XSLT if you prefer.

Quite what you want to translate these characters into is largely up to you. It depends whether they have any significance. If you want to translate them losslessly into XML 1.0, you could convert them to processing instructions such as <?char x1E?>.

  • Related