0

Within a c# project I'm sending a WebRequest to a php website, which takes the values and uses a select statement to query the DB and return an HTML page. Since there is only one value that comes back from that query, I need to assign this value to my c# code.

The source of the body-tag of the returned HTML-page (and with the StreamReader in my c#) looks like this:

<table border='1'>
    <tr><td>ValueINeed</td></tr>
</table>

How do I access the value inside this in order to assign it to a string in my c# code?

thank you.

TonyC
  • 397
  • 2
  • 6
  • 21

2 Answers2

1

If you are the author of the PHP code as well, I would suggest that you make another page that returns json or something instead, this way you would be able to avoid parsing HTML.

But if this really is what you are stuck with, I would suggest that you take a look at Html Agility Pack. Here is another quesiton here on StackOverflow that are about how to use the Html Agility Pack.

Community
  • 1
  • 1
Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
  • I don't have access to the php code so for now I will try to set up a regex. Help is still appreciated :-) – TonyC Aug 21 '12 at 06:47
  • @TonyC, **Do not use regex!** Read this: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Filip Ekberg Aug 21 '12 at 06:53
0

If the result is always the same you could just split the string or use regex. If not you may use a html parser: http://htmlagilitypack.codeplex.com/

Florian
  • 5,918
  • 3
  • 47
  • 86