public void CleanContentTrusted(AtomContent content)
    {
      Logger.Info("Cleaning content to be valid xhtml.");

      string text = content.Text;
      if (content.Type == "html")
      {
        text = "<div xmlns=\"" + Atom.XhtmlNs.NamespaceName + "\">" + text + "</div>";
      }

      Tidy tidy = new Tidy();
      /* Set the options you want */
      tidy.Options.DocType = DocType.Strict;
      //tidy.Options.DropFontTags = true; 
      tidy.Options.LogicalEmphasis = true;
      tidy.Options.Xhtml = true;
      tidy.Options.XmlOut = true;
      tidy.Options.MakeClean = true;
      tidy.Options.TidyMark = false;
      tidy.Options.QuoteNbsp = false;
      tidy.Options.NumEntities = true;
      tidy.Options.CharEncoding = CharEncoding.UTF8;
      tidy.Options.FixBackslash = true;
      tidy.Options.FixComments = true;

      TidyMessageCollection tmc = new TidyMessageCollection();
      using (MemoryStream input = new MemoryStream())
      using (MemoryStream output = new MemoryStream())
      {
        byte[] bytes = Encoding.UTF8.GetBytes(text);
        input.Write(bytes, 0, bytes.Length);
        input.Position = 0;
        tidy.Parse(input, output, tmc);
        text = Encoding.UTF8.GetString(output.ToArray());
        if (string.IsNullOrEmpty(text)) throw new FailedToCleanContentException(
          string.Format("{0} HTML Tidy Error(s)" + Environment.NewLine, tmc.Errors)
          + string.Join(Environment.NewLine,
          tmc.Cast<TidyMessage>()
          .Where(m => m.Level == MessageLevel.Error)
          .Select(m => m.ToString()).ToArray()));
      }

      //remove html/body that gets added by tidy
      //int start = text.IndexOf("<div xmlns");
      //text = text.Substring(start, text.IndexOf("</body>") - start);

      XElement div = XElement.Parse(text).Element(Atom.XhtmlNs + "body").Element(Atom.XhtmlNs + "div");

      //remove decendent xmlns that gets added by tidy
      div.Descendants().Where(d => d.Attribute("xmlns") != null && 
        d.Attribute("xmlns").Value == Atom.XhtmlNs.NamespaceName)
        .Select(d => d.Attribute("xmlns")).Remove();

      //text = text.Replace(" xmlns=\"http://www.w3.org/1999/xhtml\"", string.Empty);
      //text = "<div xmlns=\"http://www.w3.org/1999/xhtml\">" + text.Substring("<div>".Length);

      //set as xhtml
      content.Type = "xhtml";
      content.Text = div.ToString(SaveOptions.None);
    }
        public override List<SearchResult> Search(ChapterInfo chapterInfo)
        {
            string result = string.Empty;
              using (WebClient wc = new WebClient())
              {
            //NameValueCollection vars = new NameValueCollection();
            //vars.Add("txtTitle", chapterInfo.Title);
            //vars.Add("btnSearch", "Search");
            //wc.UploadValues(uri, "POST", vars);
            wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
            Uri uri = new Uri("http://www.e-home.no/metaservices/search.aspx");
            result = wc.UploadString(uri, "POST",
              //__VIEWSTATE=%2FwEPDwUKLTM3MTkwMDA5NQ9kFgICAQ9kFgICDQ88KwALAGRkg%2BhH%2F3tiaQDjnQncD1sYDdeni%2BA%3D&txtTitle=batman&btnSearch=Search&__EVENTVALIDATION=%2FwEWAwLXiqPdDAL55JyzBAKln%2FPuCgMJnDvHIVAx2tPEYdjNUbwqrR67
            string.Format("__VIEWSTATE=%2FwEPDwUKLTM3MTkwMDA5NQ9kFgICAQ9kFgICDQ88KwALAGRkg%2BhH%2F3tiaQDjnQncD1sYDdeni%2BA%3D&txtTitle={0}&btnSearch=Search&__EVENTVALIDATION=%2FwEWAwLXiqPdDAL55JyzBAKln%2FPuCgMJnDvHIVAx2tPEYdjNUbwqrR67", HttpUtility.UrlEncode(chapterInfo.Title)));
              }
              //__VIEWSTATE=%2FwEPDwUKLTM3MTkwMDA5NQ9kFgICAQ9kFgICDQ88KwALAGRkg%2BhH%2F3tiaQDjnQncD1sYDdeni%2BA%3D&txtTitle=batman&btnSearch=Search&__EVENTVALIDATION=%2FwEWAwLXiqPdDAL55JyzBAKln%2FPuCgMJnDvHIVAx2tPEYdjNUbwqrR67

              Tidy tidy = new Tidy();
              /* Set the options you want */
              tidy.Options.DocType = DocType.Strict;
              //tidy.Options.DropFontTags = true;
              tidy.Options.LogicalEmphasis = true;
              tidy.Options.Xhtml = true;
              tidy.Options.XmlOut = true;
              tidy.Options.MakeClean = true;
              tidy.Options.TidyMark = false;
              tidy.Options.QuoteNbsp = false;
              tidy.Options.NumEntities = true;
              tidy.Options.CharEncoding = CharEncoding.UTF8;
              tidy.Options.FixBackslash = true;
              tidy.Options.FixComments = true;

              TidyMessageCollection tmc = new TidyMessageCollection();
              using (MemoryStream input = new MemoryStream())
              using (MemoryStream output = new MemoryStream())
              {
            byte[] bytes = Encoding.UTF8.GetBytes(result);
            input.Write(bytes, 0, bytes.Length);
            input.Position = 0;
            tidy.Parse(input, output, tmc);
            result = Encoding.UTF8.GetString(output.ToArray());
            if (tmc.Errors > 0) throw new Exception(
              string.Format("{0} HTML Tidy Error(s)" + Environment.NewLine, tmc.Errors)
              + string.Join(Environment.NewLine,
              tmc.Cast<TidyMessage>()
              .Where(m => m.Level == MessageLevel.Error)
              .Select(m => m.ToString()).ToArray()));
            XNamespace ns = "http://www.w3.org/1999/xhtml";
            //parse titles
            XDocument searchXhtml = XDocument.Parse(result);
            Debug.Write(searchXhtml.Descendants(ns + "tr")
              .Where(tr => (tr.Attribute("id") != null && tr.Attribute("id").Value.Length == 17)).Count());

            var titles = searchXhtml.Descendants(ns + "tr")
              .Where(tr => (tr.Attribute("id") != null && tr.Attribute("id").Value.Length == 17))
              .Select(tr => new SearchResult()
              {
            Id = (string)tr.Attribute("id"),
            Name = (string)tr.Elements(ns + "td").First()
              });
            OnSearchComplete();
            return titles.ToList();
              }
        }