c# - Find Text between Html Tags -


i working on htmldocument , want text between tags:

<span>location:</span><br/>                                  50 airport road<br/> ottawa, ca <br/><br/> <span>latitude / longitude:</span><br/> 40.32083 / -71.67275<br/><br/> 

i want 2 things:

  • 50 airport road ottawa, ca
  • 45.32083 / -75.672775

how this. in advance. english not please ignore.

use html agility pack, includes dom parser - never worth writing own parser or regexs html.

http://www.nuget.org/packages/htmlagilitypack

in example below, can see how easy select element using xpath. because values want aren't in element, i'm using text() them.

if part of larger document, expand xpath reflect location in wider document.

string html = @"<span>location:</span><br/>                                      50 airport road<br/>     ottawa, ca <br/><br/>     <span>latitude / longitude:</span><br/>     40.32083 / -71.67275<br/><br/>";  htmldocument doc = new htmldocument(); doc.loadhtml(html);  // getting element (location:) var latlonglabel = doc.documentnode.selectsinglenode("span[2]");  // location split on 2 text nodes var locationvala = doc.documentnode.selectsinglenode("text()[1]").innerhtml.trim(); var locationvalb = doc.documentnode.selectsinglenode("text()[2]").innerhtml.trim();  // lat long var latlongval = doc.documentnode.selectsinglenode("text()[4]").innerhtml.trim(); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -