Why does XDocument.Parse throw NotSupportedException?

后端 未结 1 1985
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 01:02

I am trying to parse xml data using XDocument.Parse wchich throws NotSupportedException, just like in topic: Is XDocument.Parse different in Windows Phone 7? and I updated m

1条回答
  •  无人及你
    2021-01-14 01:49

    There are special symbols like '&' in e.Result.

    I just tried replace this symbols (all except '<', '>', '"') with HttpUtility.HtmlEncode() and XDocument parsed it

    UPD:

    I didn't want to show my code, but you left me no chance :)

     string y = "";
     for (int i = 0; i < s.Length; i++)
     {
          if (s[i] == '<' || s[i] == '>' || s[i] == '"')
          {
               y += s[i];
          }
          else
          {
               y += HttpUtility.HtmlEncode(s[i].ToString());
          }
     }
     XDocument document = XDocument.Parse(y);
     var options = (from option in document.Descendants("option")
          select option.Value).ToList();
    

    It's work for me on WP7. Please, do not use this code for html conversion. I wrote it quickly just for test purposes

    0 讨论(0)
提交回复
热议问题