public static XElement LoadXElement(TextReader reader)
 {
   using (HtmlReader htmlReader = new HtmlReader(reader))
   {
     return XElement.Load(htmlReader);
   }
 }
 public static XmlDocument LoadDocumentFromText(string text, string dtdName)
 {
   text = RemoveDocType(text);
   using (StringReader stringReader = new StringReader(text))
   using (HtmlReader reader = new HtmlReader(stringReader, dtdName))
   {
     XmlDocument doc = new XmlDocument();
     doc.Load(reader);
     return doc;
   }
 }