在C#中使用xpath的示例 [英] Example using xpath in C #
本文介绍了在C#中使用xpath的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个代码html:
< < span class =code-leadattribute> div id = grid style = margin-right:505px; height:700px; >
< div class = box-content style = width:99%; >
< div class = contenttitle >
< div class = left-hd >
< / div >
< div class = right-hd > $ b $bThôngtinthịtrườnggiờt< / div >
< / div >
< div class = inner >
< div style = margin-left:5px; margin-right:8px; >
< style type = text / css >
。 RadGrid_Office2007 .rgHoveredRow
{
background-color:lightyellow!important;
background-image:none!important;
}
.RadGrid_Office2007
{
border-radius:10px 10px 10px 10px;
}
.headerLeft
{
border-top-left-radius:10px!important;
}
.headerRight
{
border-top-right-radius:10px!important;
}
.RadButton_MetroTouch.rbToggleButton.rbTextButton .rbText
{
background-color:transparent;
font-size:13px;
font-family :Arial!important;
text-align:center;
font-style:italic;
颜色:蓝色;
}
< / style >
< div >
< span id = ctl00_panelContent_ctl01_ucThongTinThiTruong_lblErr > < / span >
< / div >
< div >
& lt; div id = ctl00_panelContent_ctl01_ucThongTinThiTruong_grdTT class = RadGrid RadGrid_Office2007 rgMultiHeader 样式 = 高度:700px;宽度:100%; >
< div class = rgHeaderWrapper > < div id = ctl00_panelContent_ctl01_ucThongTinThiTruong_grdTT_GridHeader class = rgHeaderDiv < span class =code-attribute> style = padding-right:16px; overflow:hidden; >
i在webbrowser上使用HtmlAgilityPack解析数据,现在我想用xpath来获取他们必须做的数据
代码HtmlAgilityPack:
var document = webBrowser1.Document;
var documentAsIHtmlDocument3 =(mshtml.IHTMLDocument3)document.DomDocument;
var htmlString = documentAsIHtmlDocument3.documentElement.innerHTML;
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(htmlString);
HtmlNodeCollection texts = doc.DocumentNode.SelectNodes( // div [ @类= '盒内容'] // DIV [@ ID = 'ctl00_panelContent_ctl01_ucThuyVan_grdGiaTriNuoc_GridData']跨度>);
string kq = ;
if (texts!= null )
{
foreach ( var item 文本)
{
kq + = item.InnerText + Environment.NewLine;
}
}
richTextBox1.Text = kq;
}
}
解决方案
http://www.codeproject。 com / Articles / 9494 / Manipulate-XML-data-with-XPath-and-XmlDocument-C
查看链接...它会帮助你
i have one code html:
<div id="grid" style="margin-right: 505px; height: 700px;">
<div class="box-content" style="width: 99%;">
<div class="contenttitle">
<div class="left-hd">
</div>
<div class="right-hd">
Thông tin thị trường giờ tới</div>
</div>
<div class="inner">
<div style="margin-left: 5px; margin-right: 8px;">
<style type="text/css">
.RadGrid_Office2007 .rgHoveredRow
{
background-color: lightyellow !important;
background-image: none !important;
}
.RadGrid_Office2007
{
border-radius: 10px 10px 10px 10px;
}
.headerLeft
{
border-top-left-radius: 10px !important;
}
.headerRight
{
border-top-right-radius: 10px !important;
}
.RadButton_MetroTouch.rbToggleButton.rbTextButton .rbText
{
background-color: transparent;
font-size: 13px;
font-family: Arial !important;
text-align: center;
font-style: italic;
color: Blue;
}
</style>
<div>
<span id="ctl00_panelContent_ctl01_ucThongTinThiTruong_lblErr"></span>
</div>
<div>
<div id="ctl00_panelContent_ctl01_ucThongTinThiTruong_grdTT" class="RadGrid RadGrid_Office2007 rgMultiHeader" style="height:700px;width:100%;">
<div class="rgHeaderWrapper"><div id="ctl00_panelContent_ctl01_ucThongTinThiTruong_grdTT_GridHeader" class="rgHeaderDiv" style="padding-right:16px;overflow:hidden;">
i have using HtmlAgilityPack parse data on webbrowser, Now I want to use xpath to get the data they must do how
code HtmlAgilityPack:
var document = webBrowser1.Document;
var documentAsIHtmlDocument3 = (mshtml.IHTMLDocument3)document.DomDocument;
var htmlString = documentAsIHtmlDocument3.documentElement.innerHTML;
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(htmlString);
HtmlNodeCollection texts = doc.DocumentNode.SelectNodes("//div[@class='box-content']//div[@id='ctl00_panelContent_ctl01_ucThuyVan_grdGiaTriNuoc_GridData']");
string kq = "";
if (texts != null)
{
foreach (var item in texts)
{
kq += item.InnerText + Environment.NewLine;
}
}
richTextBox1.Text = kq;
}
}
解决方案
http://www.codeproject.com/Articles/9494/Manipulate-XML-data-with-XPath-and-XmlDocument-C
Check the link... It will help you
这篇关于在C#中使用xpath的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文