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);
                    }

Edited 3 Years Ago by bullet_1

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>

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;)

Edited 3 Years Ago by bullet_1

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

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

This article has been dead for over six months. Start a new discussion instead.