473,411 Members | 1,918 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,411 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 7706
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.