views:

171

answers:

3

Hi,

I am saving "Children’s Music & videos" to xml

so i used the following code to convert the special symbols

        string str = "Children’s Music & videos";
        string temp = HttpUtility.HtmlEncode(str);

but the xml is not readable after saving the encoded value. How can i save this special symbols to xml

Thanks,

+2  A: 

If you have the right text in the string to start with, using the normal XML APIs should encode everything properly for you.

My guess is that you have bad text in your strings. See my Debugging Unicode Problems article for suggestions.

Jon Skeet
A: 

I believe you need to save the special character as its numerical &<nnnn>; representation.

Please see Wikipedia for more - http://en.wikipedia.org/wiki/List%5Fof%5FXML%5Fand%5FHTML%5Fcharacter%5Fentity%5Freferences

warren
You can embed arbitrary text just fine without escaping (unless it's `<` or `'`), you just need to take care of your charsets (or just use XML APIs that will automagically do The Right Thing™ for you :-))
Joey
ok - I've always relied on making sure it Does The Right Thing by forcing the encoding :)
warren
A: 

You should use the the tag <![CDATA[ ]]> to wrap around text with special characters.

Here's more on CDATA.

rogeriopvl