Abstraction of code with several Replaces

1

I have this code block:

 xml = xml.Replace("<html>", "");                                    
 xml = xml.Replace("<head>", "");
 xml = xml.Replace("</head>", "");
 xml = xml.Replace("<body>", "<certidoes>");
 xml = xml.Replace("</body>", "");
 xml = xml.Replace("</html>", "</certidoes>");

My question is: Is there any way to abstract this block in a way that is more friendly and simple?

I need to remove the tags from the html and put the tag tags.

Note: xml = is an xml that I have in the HTML page content

    
asked by anonymous 15.07.2015 / 14:51

1 answer

2

Well, I would try something that is not so much simpler, but it's much cleaner and more effective, as your file might have other tags or "junk" inside the tags.

I've seen your other questions about this your HTML file that has an XML inside.

string arquivoHTML = @"<html xmlns='http://www.w3.org/1999/xhtml'>
                        <head>
                        <meta charset='UTF-8' />
                        </head><body>
                        </body>
                        </html>";

arquivoHTML = arquivoHTML.Replace("<body>", "|").Replace("</body>", "#");
arquivoHTML = arquivoHTML.Substring(arquivoHTML.IndexOf('|')).Replace("|", "<certidoes>");
arquivoHTML = String.Concat(arquivoHTML.Substring(0, arquivoHTML.IndexOf('#')), "</certidoes>");

Console.WriteLine(arquivoHTML);
    
15.07.2015 / 15:13