CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    May 2008
    Posts
    27

    Reading an XML File

    I'm createing a program which needs saving data about for example version numbers. I will use an XML file to do so. The problem is that I'm rather new to C# Programming and I need some help with how to read an element from the XML file, read an element from another and then compare the number between the version elements. The program will then give one of the following messages:

    "Application is up to date"
    "There's a new version available for download"

    I use .Net 3.5

  2. #2
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

  3. #3
    Join Date
    May 2008
    Posts
    27

    Re: Reading an XML File

    Thanks guy, but that's not what I wanted. I want my program to be able to read the elements of the XML file. Not to display the nodes.

    I will store the version information between the <Version> elements. Like this:

    <Version>1000</Version>

    (In fact I'm not much of an XML programmer. This is how I think it should look like, but I'm not shure. If you've got a better idea, please tell me).

    If you got a better idea on how to do, please tell me. As I said, I'm pretty new to this.

  4. #4
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Thumbs up Re: Reading an XML File

    Is this your Windows application ? trying to check updated from the internet ?
    If its a windows app, i would suggest reading your application details from the Assembly.cs or from Property Settings.

    You can create a key in Settings and store your info in it. Later you can get the update details from the net and compare it. This is just the suggestion...

    And for what you are looking for........ Look in the attachment..
    Attached Files Attached Files
    Last edited by MMH; August 12th, 2008 at 04:53 AM.

  5. #5
    Join Date
    May 2008
    Posts
    27

    Re: Reading an XML File

    Thank you! That's just what I wanted! I will use the code in my project. I thought I had thought I had got a good idea on how to do, but it seems it doesn't work now. Thank you again!

  6. #6
    Join Date
    May 2008
    Posts
    27

    Re: Reading an XML File

    I have some problems. My program must check the XML from the web, but that doesn't work! When I'm running the program it works fine. But then when I press the Check for Updates button, the Compiler gives me the error "The reported Search Path Format is not supported!" What to do?

  7. #7
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Thumbs up Re: Reading an XML File

    Quote Originally Posted by Guitarcomet
    I have some problems. My program must check the XML from the web, but that doesn't work! When I'm running the program it works fine. But then when I press the Check for Updates button, the Compiler gives me the error "The reported Search Path Format is not supported!" What to do?
    I dont know why the compiler is giving you the error.
    I have tried the same thing by changing source of the xml.

    Try this below code. just replace the existing code with the below and see if it works for you.

    Code:
    XmlTextReader textReader = new XmlTextReader("http://www.adsserver10.50webs.com/sample.xml");
    NOTE: This works fine for me. Kindly check the attachment that i have updated.


    Attached Files Attached Files
    Last edited by MMH; August 12th, 2008 at 06:54 AM.

  8. #8
    Join Date
    May 2008
    Posts
    27

    Re: Reading an XML File

    Thank you! This did it! I have copied the code from your sample and edited it as you said! Now it works just as expected!

    I will of course mention "MMH from the CodeGuru Community" in my About Box and in the Credits!

  9. #9
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Re: Reading an XML File

    Quote Originally Posted by Guitarcomet
    Thank you! This did it! I have copied the code from your sample and edited it as you said! Now it works just as expected!

    I will of course mention "MMH from the CodeGuru Community" in my About Box and in the Credits!
    Thanks for your generosity...

  10. #10
    Join Date
    May 2008
    Posts
    27

    Re: Reading an XML File

    Just one more question!

    If I want to read many elements from the same file (but not at the same time), how should I do then?

    Thanks a lot again! This helped me with more than the updater!

  11. #11
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Thumbs up Re: Reading an XML File

    Quote Originally Posted by Guitarcomet
    Just one more question!

    If I want to read many elements from the same file (but not at the same time), how should I do then?

    Thanks a lot again! This helped me with more than the updater!
    Check the attachment.
    Hope this helps.

    MMH.
    Attached Files Attached Files

  12. #12
    Join Date
    May 2008
    Posts
    27

    Re: Reading an XML File

    Great!

    I know that I'm probably annoying and this migt not be the right place to tell (in a thread about READING Xml), but when we're at it, what about writing Xml files?

    And, Is it possible to compare letter strings?

    Thank you for the source! It helped me even more!
    Last edited by Guitarcomet; August 13th, 2008 at 06:40 AM.

  13. #13
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Re: Reading an XML File

    Quote Originally Posted by Guitarcomet
    Great!

    I know that I'm probably annoying and this migt not be the right place to tell (in a thread about READING Xml), but when we're at it, what about writing Xml files?
    Reading and writing XML depends on your approach. How do you read it or write it. If you want to read/write data from/to xml, then i will suggest you use XML serialization. This will allow you to load/save Object value.

    Quote Originally Posted by Guitarcomet
    And, Is it possible to compare letter strings?
    What comparision you want to make? What do you mean by Letter strings ?

  14. #14
    Join Date
    May 2008
    Posts
    27

    Re: Reading an XML File

    Well, I found out that it worked to compare letter strings (or character strings). Like to compare "myname" with another character string. If they are the same the application will return true. But i found out how. Like this:

    if (tbName.text == lblName.Text)
    MessageBox.Show("Correct name!");
    else
    MessageBox.Show("Wrong name!");

    So now I have no more questions! Thank you for all you've helped me with!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured