使用WP7将HTML转换为XML [英] Convert HTML to XML with WP7

查看:98
本文介绍了使用WP7将HTML转换为XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单情况下,想要通过HTML字符串搜索,获取一些信息。
在编写.Substing和。 IndexOf为每个我想查找和剪切掉HTML文件的元素。



Afaik我无法将HTMLtidy或HTML Agility Pack这样的dll加载到我的WP7项目中那么是否有一种更高效,更可靠的方法来搜索我的HTML字符串,而不是使用IndexOf构建Substings?

  void client_OpenReadCompleted(object发件人,OpenReadCompletedEventArgs e)
{
string document = string.Empty;
using(var reader = new StreamReader(e.Result))
document = reader.ReadToEnd();

string temp = document.Substring(document.IndexOf(Games Played),(document.IndexOf(League Games) - document.IndexOf(Games Played)));
temp =(temp.Substring(temp.IndexOf(< span>),(temp.IndexOf(< / span>) - temp.IndexOf(< span>))) ).Remove(0,6);
Int32.TryParse(temp,out leaugeGamesPlayed);
}

感谢您的帮助

Gpx

解决方案

您可以使用HTML Agility Pack,但需要转换为电话的HTML Agility Pack版本。它只能从svn仓库中获得,但它的效果很好,我在我的应用程序中使用它。



http://htmlagilitypack.codeplex.com/SourceControl/changeset/view/77494#



您可以在名为HAPPhone和HAPPhoneTest的主干下找到两个项目。您可以使用右侧的下载按钮来获取代码。它使用Linq而不是XPath来工作。


simple situation, want to search through a HTML string, get out a couple of information. Gets annoying after writing mass lines of .Substing and. IndexOf for each element i want to find and cut out of the HTML file.

Afaik i´m unable to load such dll as HTMLtidy or HTML Agility Pack into my WP7 project so is there a more efficient and reliable way to search trough my HTML string instead of building Substings with IndexOf?

    void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
       string document = string.Empty;
       using (var reader = new StreamReader(e.Result))
          document = reader.ReadToEnd();

       string temp = document.Substring(document.IndexOf("Games Played"), (document.IndexOf("League Games") - document.IndexOf("Games Played")));
       temp = (temp.Substring(temp.IndexOf("<span>"), (temp.IndexOf("</span>") - temp.IndexOf("<span>")))).Remove(0, 6);
       Int32.TryParse(temp, out leaugeGamesPlayed);
    }

Thanks for your help

Gpx

解决方案

You can use the HTML Agility Pack but you need the converted version of HTML Agility Pack for the Phone. It's only available from svn repository but it works great, I use it in my app.

http://htmlagilitypack.codeplex.com/SourceControl/changeset/view/77494#

You can find two projects under trunk named HAPPhone and HAPPhoneTest. You can use the download button to the right to get the code. It uses Linq instead of XPath to work.

这篇关于使用WP7将HTML转换为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆