473,706 Members | 7,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing HTML document to get at plain text between the <P> tags

Rob
I'm writing an application without a user interface and I have a requirement
to find the plain ASCII text between <Ptags in an HTML document which
happens to have been obtained via POP3 and parsed out of a MIME message
body.

If I had a user interface, I could drop and IE web control onto a form, load
the HTML into that and then use the document parser. I've always hated that
route as it's so clunky and anyway, this app doesn't have a user interface
(it's processing emails in a service).

Any suggestions how to go about this?

I've come across SgmlReader from here:

http://www.gotdotnet.com/Community/U...4-C3BD760564BC

This could convert the HTML document into a clean XML document which I could
then parse with the dotnet XML objects. Does this sound a sensible route?

I thought implementing a POP3 reader (easy) and internet email MIME parser
(mindblowing) was difficult enough :-)

Thanks, Rob.
Jan 3 '07 #1
9 9680
Could you just use a regular expression to pick out the pieces of text you
want?

Andrew

"Rob" <rob_nicholson@ nospam_unforget table.comwrote in message
news:ze******** **********@news fe5-win.ntli.net...
I'm writing an application without a user interface and I have a
requirement to find the plain ASCII text between <Ptags in an HTML
document which happens to have been obtained via POP3 and parsed out of a
MIME message body.

If I had a user interface, I could drop and IE web control onto a form,
load the HTML into that and then use the document parser. I've always
hated that route as it's so clunky and anyway, this app doesn't have a
user interface (it's processing emails in a service).

Any suggestions how to go about this?

I've come across SgmlReader from here:

http://www.gotdotnet.com/Community/U...4-C3BD760564BC

This could convert the HTML document into a clean XML document which I
could then parse with the dotnet XML objects. Does this sound a sensible
route?

I thought implementing a POP3 reader (easy) and internet email MIME parser
(mindblowing) was difficult enough :-)

Thanks, Rob.

Jan 4 '07 #2
Rob wrote:
I've come across SgmlReader from here:

http://www.gotdotnet.com/Community/U...4-C3BD760564BC

This could convert the HTML document into a clean XML document which I could
then parse with the dotnet XML objects. Does this sound a sensible route?
Yes, use that route to parse the HTML in a way that you can chain it to
existing XML/XPath APIs in .NET. You can either use SgmlReader or HTML
agility pack
<http://www.codeplex.co m/Wiki/View.aspx?Proje ctName=htmlagil itypack>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 4 '07 #3
Rob wrote:
I'm writing an application without a user interface and I have a requirement
to find the plain ASCII text between <Ptags in an HTML document which
happens to have been obtained via POP3 and parsed out of a MIME message
body.
Use Tidy to make it XHTML and then run XSLT to extract the paragraph text.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Jan 4 '07 #4
Rob
Could you just use a regular expression to pick out the pieces of text you
want?
Maybe... I'm not an expert on regular expressions - any references for this
particular use of regular expressions? I could just about formulate an
expression to get the text between <Pand </Pbut I also want to strip out
other tags like:

<p>Some <b>text</bstring</p>

I'm just interested in the "Some text string" bit.

Thanks, Rob.
Jan 6 '07 #5
Rob
<http://www.codeplex.co m/Wiki/View.aspx?Proje ctName=htmlagil itypack>

Thanks for the reference.

Cheers, Rob.
Jan 6 '07 #6
Rob
Thanks for the reference.

Later... the HTMLAgilityPack looks, at first glance, just what I need.

Cheers, Rob.
Jan 6 '07 #7
hehe ok - maybe thinking about this a little more would mean a fairly
complicated regular expression, especially if there are tags nested inside
:)

Andrew

"Rob" <rob_nicholson@ nospam_unforget table.comwrote in message
news:gr******** ***********@new sfe4-win.ntli.net...
>Could you just use a regular expression to pick out the pieces of text
you want?

Maybe... I'm not an expert on regular expressions - any references for
this particular use of regular expressions? I could just about formulate
an expression to get the text between <Pand </Pbut I also want to
strip out other tags like:

<p>Some <b>text</bstring</p>

I'm just interested in the "Some text string" bit.

Thanks, Rob.

Jan 8 '07 #8
kind of raw but you can remove anything that starts with < and ends with >
and everything in between. You might have to take care of any HTML tags that
are escaped e.g. &gt; for etc.

"Rob" <rob_nicholson@ nospam_unforget table.comwrote in message
news:ze******** **********@news fe5-win.ntli.net...
I'm writing an application without a user interface and I have a
requirement to find the plain ASCII text between <Ptags in an HTML
document which happens to have been obtained via POP3 and parsed out of a
MIME message body.

If I had a user interface, I could drop and IE web control onto a form,
load the HTML into that and then use the document parser. I've always
hated that route as it's so clunky and anyway, this app doesn't have a
user interface (it's processing emails in a service).

Any suggestions how to go about this?

I've come across SgmlReader from here:

http://www.gotdotnet.com/Community/U...4-C3BD760564BC

This could convert the HTML document into a clean XML document which I
could then parse with the dotnet XML objects. Does this sound a sensible
route?

I thought implementing a POP3 reader (easy) and internet email MIME parser
(mindblowing) was difficult enough :-)

Thanks, Rob.
Jan 8 '07 #9
Rob
hehe ok - maybe thinking about this a little more would mean a fairly
complicated regular expression, especially if there are tags nested inside
Actually, maybe not. I can just start to envisage an expression that finds
any <??>text</??tag and then keep calling recursively. Might work.

Then again, there are various HTML -XML libraries which might work even
better.

Cheers, Rob.
Jan 8 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2779
by: sindre hiåsen | last post by:
Hi, What I try to do is to search a text for html tags. Why. Because I want to use nl2br on the text, but since this command add br instead of all /n it is not a nice thing to add t.x. a html list inside the text. Of course it is possible to add the list and remove all space between li tags, but this is not so readable to the writer. What I try to do is also to add nl only in the plain text and inside li
4
5136
by: Lasse Edsvik | last post by:
Hello I was wondering if you guys could help me. im building a small messageboard and i want to filter all html-tags except these ones: <b> <i> <img.........> <font....> how to build such a reg exp pattern? TIA
15
6032
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my use. http://www.interactivetools.com/products/htmlarea/ This only works with IE5.5+. What I need to do is to take this html formatted text and only display part of the text on a web page (much like a news article which shows only part of the...
9
2002
by: Philip TAYLOR | last post by:
Configuring a new instance of IIS, I noticed that it allows an HTML-formatted document trailer to be appended to every document served. Unfortunately, on checking its behaviour, I find that it appends the trailer /after/ the closing </HTML> of the document, separated by a blank line. I therefore have a few questions : 1) Assuming HTML 4.01 Transitional, can anything legitimately follow the closing </HTML> tag ?
2
1841
by: Julian Jordan | last post by:
Hi I'm trying to write a system in which you can highlight some text in a form box, click a button (or press a key combination) and the text highlighted gets surrounded by a given html tag. The following works fine in IE on a PC: txt = document.selection.createRange().text;
8
2948
by: Randall Parker | last post by:
I want to generate an HTML tag that will look like: <a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For X01</a> or on a different instance where the user would be viewing "X05" it would looke like: <a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For X05</a> I'm trynig to figure out how to do that using HtmlGenericControl in C# code behind.
2
2093
by: taras.di | last post by:
Hi everyone, Is it possible to place javascript outside of <html> tags? I'm trying it on mozilla atm, and it seems to be working, but I was more worried about the older browsers. Cheers Taras
0
1731
by: suridcs | last post by:
Hi guys, i want to perform one operation like i am developing a control to compare 2 documents of any format. If i am comparing 2 HTML documents all the HTML tags are appearing in the comparision report. So i need to ignore all the HTML tags and i need to take out only the text and put it into an array. To acheive this can any body suggest how can i do this. how to ignore all the HTML tags in a document. Regards, Surendra
10
3107
by: Barry L. Camp | last post by:
Hi all... hope someone can help out. Not a unique situation, but my search for a solution has not yielded what I need yet. I'm trying to come up with a regular expression for a RegularExpressionValidator that will allow certain HTML tags: <a>, <b>, <blockquote>, <br>, <i>, <img>, <li>, <ol>, <p>, <quote>, <ul>
17
1797
by: V S Rawat | last post by:
I joined this ng and tried to post my first message that had a small php code (HTML and all). my newsserver aioe.net rejected the post saying "HTML Tags". My message was in text format, not in html format, but it obviously had html tags. Now, a php or a perl/ cgi or a javascript ng is always going to had html tags in posted messages. What is the point in not allowing Html tags?
0
8693
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9044
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7899
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4444
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4707
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2087
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.