invalid char xml

I am getting an xml which has a lot of invalid charachters like ° in c#.net.Is it possible to encode this character in code so it doesnt error out
LVL 4
Moizsaif123Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Rikin ShahConnect With a Mentor Microsoft Dynamics CRM ConsultantCommented:
Hi,

You can use XmlConvert.EncodeName method to convert invalid chars to valid xml chars-


void Main() {
    string content = "\v\f\0";
    Console.WriteLine(IsValidXmlString(content)); // False

    content = XmlConvert.EncodeName(content);
    Console.WriteLine(IsValidXmlString(content)); // True
}

static bool IsValidXmlString(string text) {
    try {
        XmlConvert.VerifyXmlChars(text);
        return true;
    } catch {
        return false;
    }
}

Open in new window

0
All Courses

From novice to tech pro — start learning today.