公告

最新评论

  • Re:ReSharper
  • I've figured out a lot of important matters by way of your current write-up. I will love to talk about that could be a circumstance in which you will certainly apply for a mortgage and never require a co-signer say for example a Regime Pupil Help Personal loan. Nonetheless in case you are getting this college loan via a typical lender then you definitely have to be made willing to have a co-signer willing to enable you to. Lenders can easily bottom part their own individual selection on the handful of factors even so the most critical will probably be your credit worthiness. There are numerous creditors that can additionally examine work background choose determined by that will playing with nearly all situations it will depend upon your current review.
    coque iphone 8 https://www.anten.fr/
  • -vvsvul@gmail.com
  • Re:FCKeditor
  • 32
  • -321
  • Re:DW版在线编辑器
  • 制作网页
  • -樱桃
  • Re:DW版在线编辑器
  • 大大
  • -吴三
  • Re:DW版在线编辑器
  • 11
  • -卷片

统计信息

资源数: 167
评论数: 77
访问次数: 1258055
建立时间: 2012-09-09

SgmlReader 用来解析HTML,并转换为XML


资源分类:.NET类库    更新日期:9/3/2008

主页:http://code.msdn.microsoft.com/SgmlReader  

语言:英文  授权形式:开源

运用.NET Framework类来解析HTML文件、读取数据并不是最容易的。虽然你可以用.NET Framework中的许多类(如StreamReader)来逐行解析文件,但XmlReader提供的API并不是“取出即可用(out of the box)”的,因为HTML的格式不规范。你可以用正则表达式(regular expression),但如果你对这些表达式运用不熟练,你可能开始时会觉得它们有些难。

Microsoft的XML大师Chris Lovett专门开发了一个SGML解析器,叫做SgmlReader,它可以解析HTML文件,甚至将它们转换成一个格式规范的结构。SgmlReader派生于XmlReader,这就是说,你可以像运用诸如XmlTextReader这样的类来解析XML文件那样来解析HTML文件。 

这是一段示例代码:

C#代码
  1. public static XmlDocument ConvertHtmlToXml(string html)   
  2. {   
  3.     using (SgmlReader sgmlReader = new SgmlReader()) {   
  4.         sgmlReader.DocType = "HTML";   
  5.         sgmlReader.InputStream = new StringReader(html);   
  6.         using (StringWriter stringWriter = new StringWriter()){   
  7.             using (XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter))   
  8.             {   
  9.                 while (!sgmlReader.EOF) {   
  10.                     xmlWriter.WriteNode(sgmlReader, true);   
  11.                 }   
  12.             }   
  13.         }   
  14.     }   
  15.   
  16.     XmlDocument xmlDoc = new XmlDocument();   
  17.     xmlDoc.LoadXml(stringWriter.ToString());   
  18.   
  19.     return xmlDoc;   
  20. }  

 

相关网址:
http://www.sifung.com/pages/743.shtm
http://msdn.microsoft.com/en-us/library/aa302299.aspx

下载页(SourceForge)  SgmlReader 1.8  MSDN代码库

评论

标题

 

姓名

 

主页

内容(请不要发布任何违反国家相关法律、违背社会伦理道德的内容)

 

验证码:  

© 2019 CodeUsing.com All Rights Reserved.   蒙ICP备12002817号-1