Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping an additional element around an existing XDocument

Let's say I have a converted HTML document, and I wanted to wrap an extra tag around the parent, so that I could read the head and body. How would I do that with C#? The file is used as an XDocument.

change

<html>
    <head>
        <!-- data -->
    </head>
    <body>
       <!-- data -->
    </body>
</html>

to

<open>
    <html>
        <head>
            <!-- data -->
        </head>
        <body>
            <!-- data -->
        </body>
   </html>
</open>
like image 838
requinard Avatar asked Oct 15 '25 00:10

requinard


1 Answers

Suppose doc is your existing document. Then you just need

var wrapped = new XElement("open", doc);

and you have an XElement with what you want.

like image 96
AakashM Avatar answered Oct 17 '25 13:10

AakashM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!