tags:

views:

219

answers:

5

Hi,

I wanna read text between <p></p> tags which comes from database field. I think there may be html reader or something which I can assign the data including html tags retrieved from database to and use innerText(<p>) or something with I can get the text between <p> tags.

Is there any way to do something like that.

Thanks in advance.

+1  A: 

I think you will need to parse the coming text from the db or search inside for the tags you want, you can also use Regex.

I mean you will need to write the innerText(<p>) your self

Amr ElGarhy
+2  A: 

Take a look at HTML Agility Pack.

Canavar
+1  A: 

Convert it to XmlDocument and use Xpath to extract the content.

Christian13467
And if the HTML contains, say, " " it will break. That's why you use the HTML Agility Pack, as HTML != XML.
Dan Diplo
+3  A: 

Whilst you could try a regular expression, the most robust way would be to use the HTML Agility Pack.

Dan Diplo
+7  A: 

Is the data html or xhtml? For xhtml, load it into XmlDocument (or XDocument etc) and access InnerText on the root element (or the element of choice). For (non-x)html, the HTML Agility Pack serves a similar purpose, allowing xpath queries etc ("//p", for example).

Marc Gravell
Marc, again you have the   problem if you try and treat XHTML as XML
Dan Diplo
Thanks,that was beautiful answer. I don't know I could do something with XmlDocument onto xHTML.
Braveyard
Dan's warning should perhaps be heeded too... fortunately, Html agility pack has a **very** similar API to XmlDocument, so it wouldn't be hard to switch if you need.
Marc Gravell