473,396 Members | 1,827 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.

Error when using XMLTextReader to read HTML

I have some simple HTML I'm trying to read with the XMLTextReader. As in the
MSDS examples, I set up a loop to read each XML node:

while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
Console.WriteLine("<{0}>", reader.Name);
break;
case XmlNodeType.Text:
Console.WriteLine(reader.Value);
break;
case XmlNodeType.Attribute:
Console.WriteLine(reader.Value);
break;
default:
Console.WriteLine(reader.NodeType);
break;
}
}

The reader moves along fine until it attempts to read the </head> node. in
this html:
<html>
<head>
<title>Sir</title>
<meta name="Author" content="Bar01">
<meta name="Description" content="Instructions">
<link href="css/results.css" media="SCREEN" rel="StyleSheet"
type="text/css" />
</head>

The error is:

System.Xml.XmlException: The 'meta' start tag on line '5' does
not match the end tag of 'head'. Line 7, position 4.
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities()
at System.Xml.XmlTextReader.Read()
at PIDProvider.Analyze.PIDrefs() in c:\vdev2\PID\Analysis.cs:line 29

What does that exception mean?

Am I missing something? Am I wrong to assume that I can read the HTML with
the XMLTextReader?

Thanks

Mitch
Nov 12 '05 #1
2 5558


Mitch wrote:
I have some simple HTML I'm trying to read with the XMLTextReader. As in the
MSDS examples, I set up a loop to read each XML node: The reader moves along fine until it attempts to read the </head> node. in
this html:
<html>
<head>
<title>Sir</title>
<meta name="Author" content="Bar01">
<meta name="Description" content="Instructions">
<link href="css/results.css" media="SCREEN" rel="StyleSheet"
type="text/css" />
</head>

The error is:

System.Xml.XmlException: The 'meta' start tag on line '5' does
not match the end tag of 'head'. Line 7, position 4.
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities()
at System.Xml.XmlTextReader.Read()
at PIDProvider.Analyze.PIDrefs() in c:\vdev2\PID\Analysis.cs:line 29

What does that exception mean?

Am I missing something? Am I wrong to assume that I can read the HTML with
the XMLTextReader?


Yes, completely wrong, HTML is an SGML application and you can't parse
HTML with an XML parser unless you author XHTML.
If you want to read HTML there is an SGML reader implementation in .NET
around, google for it.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Thanks Martin. I also found something called Tidy HTML that converts HTML to
be well formed XML. In the end though, I decided to just use regex to find
the stuff I need because I'm really not interested in the over node
structure.

Mitch
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...


Mitch wrote:
I have some simple HTML I'm trying to read with the XMLTextReader. As in the MSDS examples, I set up a loop to read each XML node:

The reader moves along fine until it attempts to read the </head> node. in this html:
<html>
<head>
<title>Sir</title>
<meta name="Author" content="Bar01">
<meta name="Description" content="Instructions">
<link href="css/results.css" media="SCREEN" rel="StyleSheet"
type="text/css" />
</head>

The error is:

System.Xml.XmlException: The 'meta' start tag on line '5' does
not match the end tag of 'head'. Line 7, position 4.
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities()
at System.Xml.XmlTextReader.Read()
at PIDProvider.Analyze.PIDrefs() in c:\vdev2\PID\Analysis.cs:line 29

What does that exception mean?

Am I missing something? Am I wrong to assume that I can read the HTML with the XMLTextReader?


Yes, completely wrong, HTML is an SGML application and you can't parse
HTML with an XML parser unless you author XHTML.
If you want to read HTML there is an SGML reader implementation in .NET
around, google for it.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3

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

Similar topics

4
by: Bill Cohagan | last post by:
I'm writing a console app in c# and am encountering a strange problem. I'm trying to use redirection of the standard input stream to read input from a (xml) file. The following code snippet is from...
3
by: Daniel | last post by:
Greetings. Just wondering if it is possible to use XmlTextReader to read off a html doc: e.g. XmlTextReader tr = new XmlTextReader ("http://localhost/test.xml"); where test.xml contains...
1
by: Jim P. | last post by:
I have a client server set of apps that can connect through socets and send data back and forth. I'm trying to get it to send XML messages back and both. Currently it works as string data. I...
0
by: SqlJunkies User | last post by:
I have pretty same problem with XmlDocument.Load(). It seems to appear after KB834623 hotfix installed. Here is the information to reproduce error: Technical info: • Windows XP Professional SP1...
7
by: SQLScott | last post by:
I have a Web Service in which I am trying to pass an XMLDocument as a parameter to one of the methods. I would like to use the XMLTextReader to read the XML but I am getting the following error: ...
5
by: Patrick | last post by:
I understand it is built in behaviour that if an ASP.NET's web.config is set to: <customErrors mode="RemoteOnly" /> then I only get a detailed error message on screen when the ASP.NET...
6
by: jasn | last post by:
Hello I am getting the following error message when I try and send an XML sting to a web service, I read somewhere that most web services prefer ascii and some throw errors when using unicode so...
1
by: Cesar | last post by:
Hello, I've developed a .NET C# web service; which has one method named, let's say, upload_your_data. This method has one parameter ( string your_data). The value that this parameter will...
4
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
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: 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
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
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...
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.