XmlReader EOF property problem
-
Hi, I'm writing some code to traverse an Xml document generated by XmlWriter. The document is extremely simple. It consists of a single element with a list of sub-elements storing some values as strings. I am having a problem using XmlReader to traverse the file to retrieve the results though. I am running Visual Studio 2005 with .NET Framework 2.0. Effectively what I want to do is to read each element, check a lookup table to see where to store the value associated with the element and move onto the next one. The problem is that I get a compile error when I attempt to use the EOF property.
int iRead; XmlReader ^xtr; xtr = XmlReader::Create(strFullPath); // Start traversing the list xtr->Read(); while (!xtr->EOF) // THIS DOESN'T WORK! { if ((xtr->NodeType == XmlNodeType::Element) && (xtr->Name == "AdminVal")) { iRead = xtr->ReadElementContentAsInt(); // store val and moves onto next node } // else if other cases here else xtr->Read(); // Move onto next node }
Now the xtr->EOF does not work at all. It will not compile with it in place but if I replace it with a while(1) then it works 100% fine (except detecting the end of the list is a problem!). I know I can tell the end of the file state from the xtr->Read() return val but if the if statement is traversed, I do not get the opportunity to read the state. The error listing is error C2059: syntax error : '(' error C2143: syntax error : missing ';' before '{' error C2039: 'xtr' : is not a member of 'System::Xml::XmlReader' c:\windows\microsoft.net\framework\v2.0.50727\system.xml.dll : see declaration of 'System::Xml::XmlReader' Is this a bug? Thanks for any assistance! -
Hi, I'm writing some code to traverse an Xml document generated by XmlWriter. The document is extremely simple. It consists of a single element with a list of sub-elements storing some values as strings. I am having a problem using XmlReader to traverse the file to retrieve the results though. I am running Visual Studio 2005 with .NET Framework 2.0. Effectively what I want to do is to read each element, check a lookup table to see where to store the value associated with the element and move onto the next one. The problem is that I get a compile error when I attempt to use the EOF property.
int iRead; XmlReader ^xtr; xtr = XmlReader::Create(strFullPath); // Start traversing the list xtr->Read(); while (!xtr->EOF) // THIS DOESN'T WORK! { if ((xtr->NodeType == XmlNodeType::Element) && (xtr->Name == "AdminVal")) { iRead = xtr->ReadElementContentAsInt(); // store val and moves onto next node } // else if other cases here else xtr->Read(); // Move onto next node }
Now the xtr->EOF does not work at all. It will not compile with it in place but if I replace it with a while(1) then it works 100% fine (except detecting the end of the list is a problem!). I know I can tell the end of the file state from the xtr->Read() return val but if the if statement is traversed, I do not get the opportunity to read the state. The error listing is error C2059: syntax error : '(' error C2143: syntax error : missing ';' before '{' error C2039: 'xtr' : is not a member of 'System::Xml::XmlReader' c:\windows\microsoft.net\framework\v2.0.50727\system.xml.dll : see declaration of 'System::Xml::XmlReader' Is this a bug? Thanks for any assistance!What is EOF defined as? I suspect it may be a function in c++ and a property in c# etc so you would need to call it like a function while(!xtr->EOF()) If that doesnt work, right click on EOF and select "Go To definition". You should be able to see how its been defined
-
What is EOF defined as? I suspect it may be a function in c++ and a property in c# etc so you would need to call it like a function while(!xtr->EOF()) If that doesnt work, right click on EOF and select "Go To definition". You should be able to see how its been defined
Go to definition gives the following: System.Boolean EOF { get; } Member of System.Xml.XmlReader Summary: When overridden in a derived class, gets a value indicating whether the reader is positioned at the end of the stream. Return Values: true if the reader is positioned at the end of the stream; otherwise, false. So it is definitely a property - like .Name which I used successfully several times. I think it is some sort of compiler/framework bug because even trying to assign a bool variable to xtr->EOF gives a compiler error. EDIT: I should add that when stepping through the debugger (with while(1) instead of while(!xtr->EOF)) and looking at the properties of xtr, the EOF property IS listed and carries the expected value.
-
Go to definition gives the following: System.Boolean EOF { get; } Member of System.Xml.XmlReader Summary: When overridden in a derived class, gets a value indicating whether the reader is positioned at the end of the stream. Return Values: true if the reader is positioned at the end of the stream; otherwise, false. So it is definitely a property - like .Name which I used successfully several times. I think it is some sort of compiler/framework bug because even trying to assign a bool variable to xtr->EOF gives a compiler error. EDIT: I should add that when stepping through the debugger (with while(1) instead of while(!xtr->EOF)) and looking at the properties of xtr, the EOF property IS listed and carries the expected value.
We just hit this one, it is because of a #define in stdio.h which defines EOF as -1. The easiest quick and dirty fix is to do a #undef EOF before the line in the file if the C library EOF define is not used further on.