如何读取标签之间的HTML [英] How Do I Read Html Between Tags
本文介绍了如何读取标签之间的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个HTML代码,标签之间的链接,我想获得这些链接到列表框。
继承人我的HTML代码
i have this html code, links between tags and i want to get those links to listbox.
heres my html code
<a name="b"></a>
<div class="block">
<h2>B</h2>
<div class="box">
<ul class="con1">
<li>
<a href="www.mylink1.com">asd1</a>
</li>
<li>
<a href="www.mylink2.com">asd2</a>
</li>
<li>
<a href="www.mylink3.com">asd3</a>
</li>
<li>
<a href="www.mylink4.com">asd4</a>
</li>
<li>
<a href="www.mylink5.com">Back to You</a>
推荐答案
您的HTML示例似乎是有效的XML ,因此您可以使用.NET FCL提供的方法之一来解析它。这是我对他们的简短概述:
It looks like your HTML sample is valid XML, so you can parse it using one of the approaches offered by .NET FCL. This is my short overview of them:
- 使用
System.Xml.XmlDocument
class 。它实现了DOM接口;如果文档的大小不是太大,这种方式是最简单和最好的。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ]。 - 使用类
System.Xml.XmlTextReader
;这是最快的阅读方式,特别是你需要跳过一些数据。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ ^ ]。 - 使用类
System.Xml.Linq.XDocument
;这是类似于XmlDocument
的最合适的方式,支持LINQ to XML Programming。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ],http://msdn.microsoft.com/en-us/library/bb387063.aspx [ ^ ]。
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the class
System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that ofXmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
这篇关于如何读取标签之间的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文