Bu yüzden bilinmeyen uzunlukta bir xml dosyası okuyorum ve her öğeyi bir liste yapısına okuyorum. Şu anda okumaya devam ettiğim dosyanın sonuna geldiğimde, bu bir istisna oluşturuyor. Şu anda sadece bu istisnayı yakaladım ve hayatımla devam ediyorum ama bunu yapmanın daha temiz bir yolu var mı?xml dosyasını okurken dosyanın sonu nasıl işlenir
try
{
while(!textReader.EOF)
{
// Used to store info from each command as they are read from the xml file
ATAPassThroughCommands command = new ATAPassThroughCommands();
// the following is just commands being read and their contents being saved
XmlNodeType node = textReader.NodeType;
textReader.ReadStartElement("Command");
node = textReader.NodeType;
name = textReader.ReadElementString("Name");
node = textReader.NodeType;
CommandListContext.Add(name);
command.m_Name = name;
command.m_CMD = Convert .ToByte(textReader.ReadElementString("CMD"),16);
command.m_Feature = Convert .ToByte(textReader.ReadElementString("Feature"),16);
textReader.ReadEndElement(); //</command>
m_ATACommands.Add(command);
}
}
catch (Exception ex)
{
//</ATAPassThrough> TODO: this is an ugly fix come up with something better later
textReader.ReadEndElement();
//cUtils.DisplayError(ex.Message);
}
xml dosyası:
<ATAPassThrough>
<Command>
<Name>Smart</Name>
<CMD>B0</CMD>
<Feature>D0</Feature>
</Command>
<Command>
<Name>Identify</Name>
<CMD>B1</CMD>
<Feature>D0</Feature>
</Command>
.
.
.
.
</ATAPassThrough>
[XmlDocument] (http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx) veya [XDocument] kullanmadığınız herhangi bir nedenle (http://msdn.microsoft .com/en-us/library/system.xml.linq.xdocument.aspx) (.Net 3.5 erişiminiz varsa tercih edilir)? –
nope sadece aşina değil – yawnobleix
XML dosyanızın bir örneğini geçebilir misiniz? –