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#
  4. Reading integer from an xml file

Reading integer from an xml file

Scheduled Pinned Locked Moved C#
helpgame-devxmltutorial
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.
  • A Offline
    A Offline
    acont
    wrote on last edited by
    #1

    I am sending game score to the web service and saving it there to xml file by using the following code: XmlTextWriter myWriter = new XmlTextWriter("highScores.xml", null); myWriter.WriteStartDocument(); myWriter.WriteStartElement("highestScore"); myWriter.WriteValue(score); myWriter.WriteEndElement(); myWriter.WriteEndDocument(); myWriter.Close(); I want to add to this function a condition to save the score only if it's higher than the score which already is in the xml. I was also trying to make another function to get this highest score from the xml, and return it to the Client. My problem is that I have no idea how to get this int (as an int) from the xml, I've tried few times on different ways bu still have no idea how to do this. Please help.

    S P 2 Replies Last reply
    0
    • A acont

      I am sending game score to the web service and saving it there to xml file by using the following code: XmlTextWriter myWriter = new XmlTextWriter("highScores.xml", null); myWriter.WriteStartDocument(); myWriter.WriteStartElement("highestScore"); myWriter.WriteValue(score); myWriter.WriteEndElement(); myWriter.WriteEndDocument(); myWriter.Close(); I want to add to this function a condition to save the score only if it's higher than the score which already is in the xml. I was also trying to make another function to get this highest score from the xml, and return it to the Client. My problem is that I have no idea how to get this int (as an int) from the xml, I've tried few times on different ways bu still have no idea how to do this. Please help.

      S Offline
      S Offline
      Seishin
      wrote on last edited by
      #2

      when you read a value from xml you get a string. to convert it to int use int.TryParse method.

      life is study!!!

      A 1 Reply Last reply
      0
      • A acont

        I am sending game score to the web service and saving it there to xml file by using the following code: XmlTextWriter myWriter = new XmlTextWriter("highScores.xml", null); myWriter.WriteStartDocument(); myWriter.WriteStartElement("highestScore"); myWriter.WriteValue(score); myWriter.WriteEndElement(); myWriter.WriteEndDocument(); myWriter.Close(); I want to add to this function a condition to save the score only if it's higher than the score which already is in the xml. I was also trying to make another function to get this highest score from the xml, and return it to the Client. My problem is that I have no idea how to get this int (as an int) from the xml, I've tried few times on different ways bu still have no idea how to do this. Please help.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        You should be clearer in what you are trying to say. 0) Shouldn't you already know whether or not the score is the high score? 1) Why not store the date and time as well as the score?

        1 Reply Last reply
        0
        • S Seishin

          when you read a value from xml you get a string. to convert it to int use int.TryParse method.

          life is study!!!

          A Offline
          A Offline
          acont
          wrote on last edited by
          #4

          Parse method worked. Thanks.

          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