Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. XmlReader EOF property problem

XmlReader EOF property problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpdotnetvisual-studioxml
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shivian
    wrote on last edited by
    #1

    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!

    L 1 Reply Last reply
    0
    • S Shivian

      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!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • L Lost User

        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

        S Offline
        S Offline
        Shivian
        wrote on last edited by
        #3

        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.

        I 1 Reply Last reply
        0
        • S Shivian

          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.

          I Offline
          I Offline
          ian__lindsay
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups