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

System.IndexOutOfRangeException in XML Reading

Hi,

I'm working on an ONIX project and when I try to validate or read XML
files C# gives me this exception:

System.IndexOutOfRangeException
at System.Xml.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 System.Xml.XmlValidatingReader.ReadWithCollectText Token()
at System.Xml.XmlValidatingReader.Read()
at ONIXImporter.XMLValidator.ValidateDTD() in
c:\projects\guai.net\bibliopola.net\user
layer\oniximporte\xmlvalidator.cs:line 94
at ONIXImporter.ONIXImporter.ValidateButton_Click(Obj ect sender, EventArgs
e) in c:\projects\\guai.net\bibliopola.net\user
layer\oniximporte\oniximporter.cs:line 482
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button,
Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMetho
ds+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason,
Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ONIXImporter.ONIXImporter.Main() in
c:\projects\guai.net\bibliopola.net\user
layer\oniximporte\oniximporter.cs:line 255

The code that I'm using is:

using System;
using System.Xml;
using System.Xml.Schema;

namespace ONIXImporter
{
public class XMLValidator
{
private bool isValid;
private string xmlFile;
private string validationMessage;

public bool IsValid{get{return isValid;}}

public string XMLFile
{
get{return xmlFile;}
set
{
value = value.Trim();
if(xmlFile != value)
{
isValid = false;
validationMessage = null;
xmlFile = value;
}
}
}

public string ValidationMessage{get{return validationMessage;}}

public XMLValidator(string xmlFile)
{
XMLFile = xmlFile;
}

public bool ValidateDTD(string xmlFile)
{
this.xmlFile = xmlFile;
return ValidateDTD();
}

public bool ValidateDTD()
{
XmlTextReader reader = new XmlTextReader(xmlFile);
reader.WhitespaceHandling = WhitespaceHandling.None;

XmlValidatingReader validator = new XmlValidatingReader(reader);
validator.ValidationType = ValidationType.DTD;

validator.ValidationEventHandler += new
ValidationEventHandler(ValidationEvent);
isValid = true;
validationMessage = null;

while(validator.Read())
System.Windows.Forms.MessageBox.Show(validator.Nod eType.ToString());
validator.Close();

return isValid;
}

private void ValidationEvent(object sender, ValidationEventArgs args)
{
isValid = false;
validationMessage += args.Message + "\r\n";
}
}
}

The XML file is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ONIXMessage SYSTEM
"http://www.editeur.org/onix/2.1/reference/onix-international.dtd">
<ONIXMessage xmlns="http://www.editeur.org/onix/ReferenceNames/"
refname="ONIXMessage" release="2.1">
<Header refname="Header">
<FromCompany refname="FromCompany">Portadas.net</FromCompany>
<FromPerson refname="FromPerson">Bernie Rabow
be**********@portadas.net</FromPerson>
<ToCompany refname="ToCompany">EDItEUR</ToCompany>
<ToPerson refname="ToPerson">David Martin</ToPerson>
<MessageNumber refname="MessageNumber">1213</MessageNumber>
<SentDate refname="SentDate">200007311330</SentDate>
<MessageNote refname="MessageNote">Prueba en Espa&ntilde;ol</MessageNote>
<DefaultLanguageOfText
refname="DefaultLanguageOfText">spa</DefaultLanguageOfText>
</Header>
<Product refname="Product">
<RecordReference refname="RecordReference">1234567890</RecordReference>
<NotificationType refname="NotificationType">03</NotificationType>
<ProductIdentifier refname="ProductIdentifier">
<ProductIDType refname="ProductIDType">02</ProductIDType>
<IDValue refname="IDValue">0816016356</IDValue>
</ProductIdentifier>
<ProductForm refname="ProductForm">BB</ProductForm>
<Title refname="Title">
<TitleType refname="TitleType">01</TitleType>
<TitleText refname="TitleText" textcase="02">British English, A to
Zed</TitleText>
</Title>
<Contributor refname="Contributor">
<SequenceNumber refname="SequenceNumber">1</SequenceNumber>
<ContributorRole refname="ContributorRole">A01</ContributorRole>
<PersonNameInverted refname="PersonNameInverted">Schur, Norman
W</PersonNameInverted>
<BiographicalNote refname="BiographicalNote">A Harvard graduate in Latin
and Italian literature, Norman
Schur attended the University of Rome and the Sorbonne before returning to
the
United States to study law at Harvard and Columbia Law Schools. Now
retired
from legal practise, Mr Schur is a fluent speaker and writer of both
British and
American English</BiographicalNote>
</Contributor>
<EditionTypeCode refname="EditionTypeCode">REV</EditionTypeCode>
<EditionNumber refname="EditionNumber">3</EditionNumber>
<Language refname="Language">
<LanguageRole refname="LanguageRole">01</LanguageRole>
<LanguageCode refname="LanguageCode">eng</LanguageCode>
</Language>
<NumberOfPages refname="NumberOfPages">493</NumberOfPages>
<BASICMainSubject refname="BASICMainSubject">REF008000</BASICMainSubject>
<AudienceCode refname="AudienceCode">01</AudienceCode>
<OtherText refname="OtherText">
<TextTypeCode refname="TextTypeCode">01</TextTypeCode>
<Text refname="Text">BRITISH ENGLISH, A TO ZED is the thoroughly updated,
revised, and
expanded third edition of Norman Schur's highly acclaimed transatlantic
dictionary
for English speakers. First published as BRITISH SELF-TAUGHT and then as
ENGLISH ENGLISH, this collection of Briticisms for Americans, and
Americanisms
for the British, is a scholarly yet witty lexicon, combining definitions
with
commentary on the most frequently used and some lesser known words and
phrases. Highly readable, it's a snip of a book, and one that sorts out -
through
comments in American - the "Queen's English" - confounding as it may
seem.</Text>
</OtherText>
<OtherText refname="OtherText">
<TextTypeCode refname="TextTypeCode">08</TextTypeCode>
<Text refname="Text">Norman Schur is without doubt the outstanding
authority on the similarities
and differences between British and American English. BRITISH ENGLISH, A
TO
ZED attests not only to his expertise, but also to his undiminished powers
to inform,
amuse and entertain. - Laurence Urdang, Editor, VERBATIM, The Language
Quarterly, Spring 1988 </Text>
</OtherText>
<Imprint refname="Imprint">
<ImprintName refname="ImprintName">Facts on File
Publications</ImprintName>
</Imprint>
<Publisher refname="Publisher">
<PublishingRole refname="PublishingRole">01</PublishingRole>
<PublisherName refname="PublisherName">Facts on File Inc</PublisherName>
</Publisher>
<PublicationDate refname="PublicationDate">1987</PublicationDate>
<Measure refname="Measure">
<MeasureTypeCode refname="MeasureTypeCode">01</MeasureTypeCode>
<Measurement refname="Measurement">9.25</Measurement>
<MeasureUnitCode refname="MeasureUnitCode">in</MeasureUnitCode>
</Measure>
<Measure refname="Measure">
<MeasureTypeCode refname="MeasureTypeCode">02</MeasureTypeCode>
<Measurement refname="Measurement">6.25</Measurement>
<MeasureUnitCode refname="MeasureUnitCode">in</MeasureUnitCode>
</Measure>
<Measure refname="Measure">
<MeasureTypeCode refname="MeasureTypeCode">03</MeasureTypeCode>
<Measurement refname="Measurement">1.2</Measurement>
<MeasureUnitCode refname="MeasureUnitCode">in</MeasureUnitCode>
</Measure>
<SupplyDetail refname="SupplyDetail">
<SupplierSAN refname="SupplierSAN">1234567</SupplierSAN>
<AvailabilityCode refname="AvailabilityCode">IP</AvailabilityCode>
<Price refname="Price">
<PriceTypeCode refname="PriceTypeCode">01</PriceTypeCode>
<PriceAmount refname="PriceAmount">35.00</PriceAmount>
</Price>
</SupplyDetail>
</Product>
</ONIXMessage>
For XMLSpy is a valid file. Please help me. Thanks.
Nov 15 '05 #1
0 1762

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

Similar topics

9
by: Tylius | last post by:
This one line is causing the issue, I've searched all over the net, but I can't seem to figure out why public static void Main(string args) { Console.WriteLine("Dice Roller"); try { int...
2
by: | last post by:
Using the following against a sql database, I get a system.IndexOutOfRangeException for the column name Add_Date which is valid field name and is a datetime field. All the other columns work ok. ...
5
by: Michael Primeaux | last post by:
I have a simple .NET 2.0 web service created with VS.NET 2005 with a single web method with the following signature: void HelloWorld(Guid parameter1); When calling this method I receive the...
0
by: Susan | last post by:
I have an issue with the System.Collections.Generic.List that I can't find anywhere else... My website suddenly starts giving off System.IndexOutOfRangeException: Index was outside the bounds of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.