472,972 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,972 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 5504


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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.