By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,566 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

System.IndexOutOfRangeException in XML Reading

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.