1

My html structure as below

<td class="opps">1:2</td>

I am trying split value of td with XPath as below

.//*[contains(@class, 'opps')]/text()[normalize-space(substring-after(., ':'))]
.//*[contains(@class, 'opps')]/text()[normalize-space(substring-before(., ':'))]

But value returns 1:2

How can i extract 1 and 2 separately?

I am also using HtmlNodeNavigator and HtmlAgilityPack.

What is the wrong?

Thank you in advance.

Kerberos
  • 1,228
  • 6
  • 24
  • 48
  • Silly question, but if you can get the `1:2` value, why not split it in C# after parsing it out? – Oded Mar 29 '13 at 13:11
  • look at this answer on `SO` someone asked a similar question with a provided solution http://stackoverflow.com/questions/3964642/using-substring-after-to-search-text-in-xpath-query – MethodMan Mar 29 '13 at 13:16
  • @Oded Beacuse i would like to extract value with XPath. – Kerberos Mar 29 '13 at 13:23
  • 1
    Not really answering my question. "Because I want to". Do you have any specific technical issue that means you must do it in XPath? – Oded Mar 29 '13 at 13:24
  • it applies using XPATH unless I am reading what he is wanting incorrectly.. – MethodMan Mar 29 '13 at 13:24
  • @DJKRAZE Thank you. i tried that question's suggestions but i doesn't work. – Kerberos Mar 29 '13 at 13:24
  • @Oded OK i changed my answer. Because my application's workflow need to use XPath. – Kerberos Mar 29 '13 at 13:27

2 Answers2

2

i found a solution after more search.

if use HtmlNodeNavigator or XPathNavigator, solution is possible as below

string _result1 = <HtmlNodeNavigator>.Evaluate("substring-after(.//*[contains(@class, 'opps')]/text(), ':')") as string; 
string _result2 = <XPathNavigator>.Evaluate("substring-before(.//*[contains(@class, 'opps')]/text(), ':')") as string;
Kerberos
  • 1,228
  • 6
  • 24
  • 48
  • Kudos for finding your own answer. I've deleted mine. – Tomalak Mar 31 '13 at 09:38
  • Well, I've been dead wrong in saying that it was impossible (because I was only thinking in terms of the Agility Pack and `HtmlAgilityPack.HtmlDocument`), so it's only fair. – Tomalak Mar 31 '13 at 22:41
0

Just in case, you can use c# method for this too. For example;

string strVal = "1:2";
string[] splitedStrArr = strVal.Split(':'); 
// you have now 2 elements inside the array. You can use it separately
Mehmet Taha Meral
  • 3,315
  • 28
  • 30