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.

7
  • Silly question, but if you can get the 1:2 value, why not split it in C# after parsing it out? Commented Mar 29, 2013 at 13:11
  • look at this answer on SO someone asked a similar question with a provided solution stackoverflow.com/questions/3964642/… Commented Mar 29, 2013 at 13:16
  • @Oded Beacuse i would like to extract value with XPath. Commented Mar 29, 2013 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? Commented Mar 29, 2013 at 13:24
  • it applies using XPATH unless I am reading what he is wanting incorrectly.. Commented Mar 29, 2013 at 13:24

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Kudos for finding your own answer. I've deleted mine.
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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.