I am writing the match case for xml tags inorder to show it as html in a div container.
where in an xml file i will have emphasis tags for bold,italic,undeline etc.
I want to know how to write match the xml tags if it contains nested emphasis tags.
for example when i match like
if(Regex.IsMatch(l,"( < Emphasis Type=\"Italic\"> .+? < /Emphasis> )",RegexOptions.IgnoreCase))
I will get problem when I have the xml as:
< Emphasis Type=\"Italic\">
< Emphasis Type=\"bold\"> sdjskdjskdj < /Emphasis>
sjdksjds ksjd kdjs djsd ksdj kdjskd jdsd
< Emphasis>
This is my sample code
***********************
{
Regex r =new Regex("( < Emphasis Type=\"Italic\"> .+? < /Emphasis> )",RegexOptions.IgnoreCase);
Match m =r.Match(l);
Group g;
while(m.Success)
{
g=m.Groups[0];
l =l.Remove(g.Index,g.Length);
string k=g.Value;
k=Regex.Replace(k," < Emphasis Type=\"Italic\"> ","",RegexOptions.IgnoreCase);
k=Regex.Replace(k," < /Emphasis> ","",RegexOptions.IgnoreCase);
l =l.Insert(g.Index," < EM> "+k+" < /EM> ");
m=r.Match(l);
}
}
if(Regex.IsMatch(l,"( < Emphasis Type=\"Underline\"> .+? < /Emphasis> )",RegexOptions.IgnoreCase))
{
Regex r =new Regex("( < Emphasis Type=\"Underline\"> .+? < /Emphasis> )",RegexOptions.IgnoreCase);
Match m =r.Match(l);
Group g;
while(m.Success)
{
g=m.Groups[0];
l =l.Remove(g.Index,g.Length);
string k=g.Value;
k=Regex.Replace(k," < Emphasis Type=\"Underline\"> ","",RegexOptions.IgnoreCase);
k=Regex.Replace(k," < /Emphasis> ","",RegexOptions.IgnoreCase);
l =l.Insert(g.Index," < U> "+k+" < /U> ");
m=r.Match(l);
}
}
can any one help me in writing generalised Regex for N number of nested emphasis tags.
Thanks