473,386 Members | 1,674 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,386 software developers and data experts.

XmlTextReader fails on reading DOCTYPE?

I am hoping someone on this list can shed some light on
the below issue for me. I am using XmlTextReader to read
from an XML file. Unfortunately, an exception is thrown
("Index was outside the bounds of the array.") when the
reader reaches the DOCTYPE. If I remove it everything
works fine. Should I be handling the DOCTYPE someway
before I read the DOCTYPE? Any insight would be greatly
appreciated. I have provided a sample XML document plus
some simple code.

Cheers,

------------------ Begin Document ------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE ONIXmessage
SYSTEM "http://www.editeur.org/onix/2.0/short/onix-
international.dtd">
<ONIXmessage>
<header>
<m173>3983939393</m173>
<m174>Me Vendor</m174>
<m175>Full Name</m175>
<m180>1</m180>
<m182>200306221017</m182>
<m183>Description</m183>
</header>
<product>
<a001>0761501877</a001>
<a002>04</a002>
<b004>0761501877</b004>
<b005>9780761501862</b005>
<b012>BC</b012>
<b028>The Michael Story</b028>
<b029>What's It Like To Be Me</b029>
<contributor>
<b034>1</b034>
<b035>A01</b035>
<b036>Michael Muffett</b036>
<b037>Muffett, Michael</b037>
<b039>Michael</b039>
<b040>Muffett</b040>
<b043>L.</b043>
</contributor>
<b059>eng</b059>
<b061>1000</b061>
<b064>FIC000000</b064>
<b079>Muffett Publishing</b079>
<imprint>
<b241>02</b241>
<b243>PL</b243>
<b079>Muffett Publishing</b079>
</imprint>
<b081>Muffett Publishing</b081>
<b003>19951018</b003>
<supplydetail>
<j136>2013975</j136>
<j137>Random House</j137>
<j138>CA</j138>
<j141>IP</j141>
<j143>20031018</j143>
<j145>24</j145>
<price>
<j148>01</j148>
<j151>260.95</j151>
<j152>CAD</j152>
</price>
</supplydetail>
</product>
</ONIXmessage>
-------------------- End Document ----------------------

-------------------- Begin Code ------------------------
public static void loadDocument(string fileName)
{
XmlTextReader onixTextReader
= new XmlTextReader(fileName);
try
{
onixTextReader.Read();
MessageBox.Show("Declaration: " +
onixTextReader.NodeType.ToString());
onixTextReader.Read();
MessageBox.Show("Second
Line WhiteSpace: " + onixTextReader.NodeType.ToString());
onixTextReader.ReadString
();
MessageBox.Show
(onixTextReader.NodeType.ToString());
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
---------------------- End Code --------------------------
Nov 12 '05 #1
3 4189
Have you gotten this solved?

I don't think the problem is the DOCTYPE element itself. It is in the
XMLNodeType enum, and the XMLTextReader.Read documentation happens ot
include it. Which specific line of code throws the exception?

--
Kathleen Dollard
Microsoft MVP
Author "Code Generation in Microsoft .NET"
"keldan" <an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl...
I am hoping someone on this list can shed some light on
the below issue for me. I am using XmlTextReader to read
from an XML file. Unfortunately, an exception is thrown
("Index was outside the bounds of the array.") when the
reader reaches the DOCTYPE. If I remove it everything
works fine. Should I be handling the DOCTYPE someway
before I read the DOCTYPE? Any insight would be greatly
appreciated. I have provided a sample XML document plus
some simple code.

Cheers,

------------------ Begin Document ------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE ONIXmessage
SYSTEM "http://www.editeur.org/onix/2.0/short/onix-
international.dtd">
<ONIXmessage>
<header>
<m173>3983939393</m173>
<m174>Me Vendor</m174>
<m175>Full Name</m175>
<m180>1</m180>
<m182>200306221017</m182>
<m183>Description</m183>
</header>
<product>
<a001>0761501877</a001>
<a002>04</a002>
<b004>0761501877</b004>
<b005>9780761501862</b005>
<b012>BC</b012>
<b028>The Michael Story</b028>
<b029>What's It Like To Be Me</b029>
<contributor>
<b034>1</b034>
<b035>A01</b035>
<b036>Michael Muffett</b036>
<b037>Muffett, Michael</b037>
<b039>Michael</b039>
<b040>Muffett</b040>
<b043>L.</b043>
</contributor>
<b059>eng</b059>
<b061>1000</b061>
<b064>FIC000000</b064>
<b079>Muffett Publishing</b079>
<imprint>
<b241>02</b241>
<b243>PL</b243>
<b079>Muffett Publishing</b079>
</imprint>
<b081>Muffett Publishing</b081>
<b003>19951018</b003>
<supplydetail>
<j136>2013975</j136>
<j137>Random House</j137>
<j138>CA</j138>
<j141>IP</j141>
<j143>20031018</j143>
<j145>24</j145>
<price>
<j148>01</j148>
<j151>260.95</j151>
<j152>CAD</j152>
</price>
</supplydetail>
</product>
</ONIXmessage>
-------------------- End Document ----------------------

-------------------- Begin Code ------------------------
public static void loadDocument(string fileName)
{
XmlTextReader onixTextReader
= new XmlTextReader(fileName);
try
{
onixTextReader.Read();
MessageBox.Show("Declaration: " +
onixTextReader.NodeType.ToString());
onixTextReader.Read();
MessageBox.Show("Second
Line WhiteSpace: " + onixTextReader.NodeType.ToString());
onixTextReader.ReadString
();
MessageBox.Show
(onixTextReader.NodeType.ToString());
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
---------------------- End Code --------------------------

Nov 12 '05 #2
Sadly I have not solved this issue yet. For the life of me I can't
understand what is wrong. The the pointer for the reader can't seem
to read past the DOCTYPE. If i use a while loop:

while(!reader.EOF)
{
reader.Read()
MessageBox.Show(reader.NodeType.ToString());
}

It will read the XML declaration, the whitespace that comes after the
declaration and then an exception is thrown from the reader.Read()
when the pointer for the reader points to the next node (which I am
assuming is the DOCTYPE).

The output from the Stack Trace is:

at System.XmlScanner.ScanDtdContent()
at System.Xml.Schema.DtdParser.ScanDtdContent()
at System.Xml.Schema.DtdParser.ParseDtdContent()
at System.Xml.Schema.DtdParser.ParseDocTypeDecl()
at System.Xml.Schema.DtdParser.Parse()
at System.Xml.XmlTextReader.ParseDtd(XmlScanner scanner)
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseRoot()
at System.Xml.XmlTextReader.Read()
at MainMenuForm1.loadDocument(String fileName) in C:\vs projects\
mainmenuform\form1.cs:line 326

line 326 is reader.Read();

As I said earlier for the life of me I can't understand why it can't
read past the DOCTYPE. It's such a simple while loop statement that
just outputs the nodetype to a MessageBox. I am new to using the
System.Xml namespace so any more light you can shed on this matter
will be greatly appreciated - I am at quite confused with this
problem. I have gone over the online documentation, visited
messageboards and can find no solution to this problem.

Cheers,

Mick

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 12 '05 #3


keldan wrote:
Sadly I have not solved this issue yet. For the life of me I can't
understand what is wrong. The the pointer for the reader can't seem
to read past the DOCTYPE. If i use a while loop:

while(!reader.EOF)
{
reader.Read()
MessageBox.Show(reader.NodeType.ToString());
}

It will read the XML declaration, the whitespace that comes after the
declaration and then an exception is thrown from the reader.Read()
when the pointer for the reader points to the next node (which I am
assuming is the DOCTYPE).

The output from the Stack Trace is:

at System.XmlScanner.ScanDtdContent()
at System.Xml.Schema.DtdParser.ScanDtdContent()
at System.Xml.Schema.DtdParser.ParseDtdContent()
at System.Xml.Schema.DtdParser.ParseDocTypeDecl()
at System.Xml.Schema.DtdParser.Parse()
at System.Xml.XmlTextReader.ParseDtd(XmlScanner scanner)
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseRoot()
at System.Xml.XmlTextReader.Read()
at MainMenuForm1.loadDocument(String fileName) in C:\vs projects\
mainmenuform\form1.cs:line 326

line 326 is reader.Read();


As far as I see it currently the XmlTextReader reads in the DTD from
http://www.editeur.org/onix/2.0/shor...ernational.dtd and fails
to parse it.
I tried validating the XML in your first post with MSXML 4 and it didn't
have any problems with the DTD so there might be a bug in .NET's DTD parser.

--

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

Nov 12 '05 #4

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

Similar topics

4
by: Meir S. | last post by:
I think the following is a bug in XmlTextReader: I need to process large XMLs, that are typically constructed of many small elements nested in the root element. Each inner element represents a...
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...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
2
by: Stephen Gutknecht \(RoundSparrow\) | last post by:
XmlTextReader against a stream no longer works. This breaks the open source jabber-net and other software. Several people have confirmed that what works on dotNet 1.1 fails on dotNet 1.1 SP1. ...
2
by: ecomputerdelicacy | last post by:
Compact Framework SP3 (and I think also SP2 and SP1) XmlTextReader does not handle !DOCTYPE and (maybe?) rdf elements. How can I get the XmlTextReader to read these without issuing a...
3
by: Kjeld | last post by:
My scenario: I'm using an XmlTextReader to Deserialize serveral classes from a single xml document. Every class i pass the source stream, containing the xml. Each class subsequently creates an...
2
by: Q | last post by:
I am feeding XmlTextReader a URL that returns the XML that then gets parsed. The URL forms a query that affects how much data is returned in XML but not the format of the data. The problem is...
2
by: XML reading with XMLTextReader | last post by:
im trying to read an xml file which is in the wwwroot folder.im using IIS on XP Prof. my code is...
1
by: TheDude5B | last post by:
hi, I have a function which reads the xml from a web url into the XmlTextReader, and then I work my way through the reader producing html from the different nodes. All the code works fine when I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.