问题
I'm trying to find the nextSibling innerText of a specific tag, but I can't get the proper value when I try to parse an html string which contains white spaces or new lines
here is my code:
private string getTableTdValue()
{
/*If I strip all white space between tag I get proper results
string myHtml =
"<td align='right' width='186'>Text1</td><td align='center' width='51'>Here the result I want to get</td><td width='186'>Text2</td>";*/
string myHtml =
@"
<td align='right' width='186'>Text1</td>
<td align='center' width='51'>Here the result I want to get</td>
<td width='186'>Text2</td>";
HtmlDocument doc = new HtmlDocument();
HtmlNodeCollection cols = doc.DocumentNode.SelectNodes("//td[@width='186']");
var tdValue = string.Empty;
foreach (HtmlNode col in cols)
{
if (col.InnerText == "Text1")
{
tdValue = col.NextSibling.InnerText;
}
}
return tdValue;
}
Can I get nextSibling value whithout requiring to remove all whitespaces between tags?
来源:https://stackoverflow.com/questions/17785682/html-agility-pack-nextsibling-not-finding-element-if-there-are-white-spaces-betw