How can i easily sanitize the values I pass into the Value property of an XAttri开发者_如何学Pythonbute.
Here's an extension method to clean away your trouble. /0 is not allowed in XML. I'm not sure if other chars are also disallowed, but I believe not. Probably best to start at ' '.
void Main()
{
    Console.WriteLine("123\0394".XmlSanitize());
}
public static class XmlHelpers
{
    public static string XmlSanitize(this string badString)
    {
        return new String(badString.Where(c => c >=' ').ToArray());
    }
}
You could try:
string value = "!@#$%^&*()123%^&*(!@#\(*!&10987"
value = System.Security.SecurityElement.Escape(value);
This will escape characters that are invalid as XML attribute values.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论