I'm doing some transforms using xlinq and some of those transforms can result in leaving empty elements in the document.
Once I am done all of those transforms, how can I query an xdocument for all empty elements?
In other words; if I remove all <a>
tags which happen to be the only element inside an <li>
tag, how do I remove the empty <li>
?
Before:
XDocument.Parse(@"<body>
<ul><li><a href="#">Joy</a></li></ul>
<p>Hi.</p>
</body>").Descendants("a").Remove();
After:
<body>
<ul><li/></ul>
<p>Hi.</p>
</body>
I would prefer:
<body>
<p>Hi.</p>
</body>