views:

37

answers:

2

Hello

I have xml file with TAG like this:

<Question>dzia&amp;#322;owa</Question>

I'm reading this file using XmlTextReader and for this TAG I get something like this:

dzia&#322;owa

How to replace html entity numbers inside my xml to get something like this: "działowa"?

A: 

The only HTML entity in your sample is &amp;. You've then got some normal text that says #322;. You either want

<Question>dzia&amp;&#322;owa</Question>

which would give "dzia&łowa" (probably not what you want)

or

<Question>dzia&#322;owa</Question>

which would give "działowa"

Graham Clark
is entity number for char 'ł'I would like to get 'działowa'
UGEEN
Graham Clark
I need first to decode to and then decode to 'ł' char. 2-steps decoding i think - I don't see a better way.
UGEEN
A: 

I think I solved part of the problem (encoding &#number; to char):

public static string EntityNumbersToEntityValues(string s)
        {
            Match match = Regex.Match(s, @"&#(\d+);", RegexOptions.IgnoreCase);
            while(match.Success)
            {
                string v = match.Groups[1].Value;
                string c = char.ConvertFromUtf32(int.Parse(v));
                s = Regex.Replace(s, string.Format("&#{0};", v), c);
                match = match.NextMatch();
            }           
            return s;
        }
UGEEN