I am using following code, it replaces entities in whole html file.
But I want to replace only in between specified tags(i.e <div>......</div>)
please help me

{
                        FileInfo n = new FileInfo(inputpath);

                        string initContent = File.ReadAllText(file);

                    int contentLength = initContent.Length;
                        Matches m;

       while ((m = Regex.Matches(initContent, "[^a-zA-Z0-9<>=./\\s(&#\\d+;)-]")).Value != String.Empty)
       initContent = initContent.Remove(m.Index, 1).Insert(m.Index, string.Format("&#{0};", (int)m.Value[0]));

                        File.WriteAllText(outpath, initContent);
                    }

A sample of the beginning data and a sample of the desired ending data would be very helpful

The following is an example code. I want to replace entities in between <div>.....</div>
tags only

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>chapter06</title>
<link rel="stylesheet" href="ebook_style.css" type="text/css"/>
</head>
<body>
<div>
<h2 class="chapternumber"><small>SIX</small></h2>
<h2 class="chaptertitle">IS @ @ @ @ @ THERE A     N EVENT IN HEGEL?</h2>
<h2 class="subheadtitle"><i> $ $ $ $ Malabou,  ^ ^ ^ ^Plasticity, ÃÜéæ and Perhaps&</i></h2>
<p class="epigraph"><i>Where the @ @ @ @ @ corpse is, there the ÃÜéæ vultures will gather.</i></p>
</div>
<p class="epigraph-right"><small>LUKE</small> 17:37</p>
<h3 class="subheadhead"><small>H                      EGEL, PERHAPS</small></h3>
<p class="indent">Which @ @ @ I will examine $ $ below.</p>
</body>
</html>

What is the desired outcome you want from that sample. Saying "replace entities" doesn't say much

I want all entities such as Ã Ü é æ @ @ @ @ @ ^ ^ and so on ........ (any entity) in between <div> tags must be replaced with Entity Number (&#34;
&#39; &#38; &#60; &#62;)

I want all entities such as Ã Ü é æ @ @ @ @ @ ^ ^ and so on ........ (any entity) in between <div> tags must be replaced with Entity Number i.e "
' & < > .....(something like this)
and remaining must be changed

Are you sure the code you provided is correct? It doesn't seem to be able to compile.

The first provided code is in C# which replaces entities with entity number in a html file(provided second).The provided html file is input file in which changes has to be made

That much is obvious, but like I said the C# code doesn't compile