473,396 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Html parser

Hi, I am using a program that is ultra paranoid about start and end html
tags.

For example

<p>This is a test
<br>A new line

The above code causes the program to fail

<p>This is a test</p>
<br>A new line</br>

The above code works fine.

Does anyone have a short routine that looks for a start HTML tag and if a
matching end tag does not exist inserts an end tag? I could write one myself
but rather than reinventing the wheel and all that ;)

Thanks in advance
Mark
Jul 21 '05 #1
3 7705
Hi Mark,

If you look for a simple solution, you could then use Microsoft IE's HTML
parser which is pretty smart in dealing with non-closed tags. I'd also say
such a routine won't be short as the parser should keep track of each
non-closed tag and its context to suggest proper closing tags in proper
places.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mark" <ma**@yahoo.comN0SPAM> wrote in message
news:bj**********@lust.ihug.co.nz...
Hi, I am using a program that is ultra paranoid about start and end html
tags.

For example

<p>This is a test
<br>A new line

The above code causes the program to fail

<p>This is a test</p>
<br>A new line</br>

The above code works fine.

Does anyone have a short routine that looks for a start HTML tag and if a
matching end tag does not exist inserts an end tag? I could write one myself but rather than reinventing the wheel and all that ;)

Thanks in advance
Mark


Jul 21 '05 #2
if you need to work with existing html then consider using tidycom or the c#
wrapper for it (http://www.mattstan.pwp.blueyonder.c...y/tidycs.html),
if you're manipulating existing html then use the dom exposed by mshtml, if
you're creating html from scratch, then just use an xml dom.

r.

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:ea**************@tk2msftngp13.phx.gbl...
Hi Mark,

If you look for a simple solution, you could then use Microsoft IE's HTML
parser which is pretty smart in dealing with non-closed tags. I'd also say
such a routine won't be short as the parser should keep track of each
non-closed tag and its context to suggest proper closing tags in proper
places.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mark" <ma**@yahoo.comN0SPAM> wrote in message
news:bj**********@lust.ihug.co.nz...
Hi, I am using a program that is ultra paranoid about start and end html
tags.

For example

<p>This is a test
<br>A new line

The above code causes the program to fail

<p>This is a test</p>
<br>A new line</br>

The above code works fine.

Does anyone have a short routine that looks for a start HTML tag and if a matching end tag does not exist inserts an end tag? I could write one

myself
but rather than reinventing the wheel and all that ;)

Thanks in advance
Mark

Jul 21 '05 #3
Thanks for your help
Regards
Mark
Jul 21 '05 #4

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

Similar topics

1
by: Mitchua | last post by:
I am trying to use HTML::Parser to parse an HTML file, remove all HTML tags (including comments, etc.), replace all ENTITIES (e.g. &amp), and put the result into a variable as a string. I figure...
0
by: Himanshu Garg | last post by:
Hello, I am using HTML::Parser to extract text from html pages from http://bbc.co.uk/urdu/ However the encoding of the input text seems to change to some unknown encoding in the output. The...
3
by: Himanshu Garg | last post by:
Hello, I am trying to pinpoint an apparent bug in HTML::Parser. The encoding of the text seems to change incorrectly if the locale isn't set properly. However Parser.pm in the directory...
14
by: WUV999U | last post by:
Hi I am fairly familiar in C but not much. I want to know how I can write a html parser in C that only parses for the image file in the html file and display or print all the images found in...
2
by: Craig Kenisston | last post by:
Hi, Could someone recommend any decedent html parser ? All what I need to do is to extract the links from a given page. I've found several tools in codeproject but all seems to be a bit...
3
by: Mark | last post by:
Hi, I am using a program that is ultra paranoid about start and end html tags. For example <p>This is a test <br>A new line The above code causes the program to fail
0
by: icoba | last post by:
Hi, I am parsing html documents using the html parser from libxml2, and if the encoding is included in the document it works perfectly but if it is not, I think it does not work well (probably...
3
by: SEGACO | last post by:
Hi, Can someone tell me if C# includes something to parse HTML? Thanks.
2
by: David Virgil Hobbs | last post by:
Loading text strings containing HTML code into an HTML parser in a Javascript/Jscript I would like to know, how one would go about loading a text string containing HTML code, so as to be able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.