Click to See Complete Forum and Search --> : Reading an XML File


Guitarcomet
August 12th, 2008, 02:58 AM
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

MMH
August 12th, 2008, 03:11 AM
Look in to the following :

http://support.microsoft.com/kb/307548

http://www.c-sharpcorner.com/UploadFile/mahesh/ReadWriteXMLTutMellli2111282005041517AM/ReadWriteXMLTutMellli21.aspx

Guitarcomet
August 12th, 2008, 04:08 AM
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.

MMH
August 12th, 2008, 04:27 AM
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..

Guitarcomet
August 12th, 2008, 05:19 AM
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!

Guitarcomet
August 12th, 2008, 06:23 AM
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?

MMH
August 12th, 2008, 06:39 AM
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.


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. :wave:

Guitarcomet
August 12th, 2008, 07:07 AM
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!;)

MMH
August 12th, 2008, 07:17 AM
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... :)

Guitarcomet
August 13th, 2008, 04:20 AM
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!:)

MMH
August 13th, 2008, 05:35 AM
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.

Guitarcomet
August 13th, 2008, 05:54 AM
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!

MMH
August 13th, 2008, 07:35 AM
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.


And, Is it possible to compare letter strings?


What comparision you want to make? What do you mean by Letter strings ?

Guitarcomet
August 14th, 2008, 03:09 AM
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!