Jump to content

Recommended Posts

Is anyone good at XML and C#? Would anyone be able to help or create a program to read and compare xml documents?

Share this post


Link to post
Share on other sites

XML is pretty well supported in C#, just read the docs for XMLDocument and XMLReader from System.Xml and you should be pretty good to go.

Share this post


Link to post
Share on other sites

I figured out how to read the xml and pull the data i need. Now i'm not sure the best way to display it.

 

What should i use to feed my data into to display it? This is what i'm looking to do. Should i load everything into a list... dataset...something else?

 

parent name | version | file name

clone name | version | file name

parent name | version | file name

etc....

Share this post


Link to post
Share on other sites

That's a little unclear, is the data formatted so every parent has clone children and if so is it a fixed amount of variable? If it's just collections of three things then just use an array of tuples Tuple<Type1,Type2,Type3>[].

Sorry if this isn't helpful I don't fully understand your intentions with the data.

Share this post


Link to post
Share on other sites

What i'm trying to do is make a program that will let me know what i'm missing from my front end when I update Mame. The front end is not reliable when importing new roms so i have to do it manually, and since Mame changes things frequently it is a pain.

 

there is not always a parent - clone relationship. sometimes it will be just a parent. Sometimes the parent can have multiple clones or just one clone.

I want my program to basically look like this... but i'm going to have it only display what is different in my lists. As you can see there are different amounts of clones (they call them orphans), and not all have clones (above the first parent).

mame-roms2.png

 

This is what i have so far, and it is showing correct data, but i have to step through it each time. I'm just not sure how to get all the individual data listed at the same time.

XElement root = XElement.Load(@"C:\source\repos\WindowsFormsApp1\WindowsFormsApp1\test.xml");
            
            IEnumerable < XElement > games = root.Elements();


            foreach (var game in games)

            {
                try
                {
                    string pName = game.Element("Title").Value + " " + game.Element("Version").Value;
                    string pRom = System.IO.Path.GetFileNameWithoutExtension(game.Element("ApplicationPath").Value);
                    var clone = from nm in root.Elements("AdditionalApplication")
                                where (string)nm.Element("GameID") == game.Element("ID").Value
                                select nm;
                        MessageBox.Show("Parent: " + pName + " Rom: " + pRom);

                    try
                    {
                        foreach (var game2 in clone)
                        {
                            string cName = game2.Element("Name").Value;
                            string cRom = System.IO.Path.GetFileNameWithoutExtension(game2.Element("ApplicationPath").Value);
                            MessageBox.Show("Parent: " + pName
                                + " Rom: " + pRom + "\n"
                                + " " + "Clone: " + cName
                                + " Rom: " + cRom);
                        }
                    }

                    catch { }
                }

 

Share this post


Link to post
Share on other sites

Ok everything is working properly at least from my xml side. Now i'm just not sure how to list everything in one big list.

6d661797aa019f04a3a563ad28b30288.png

ac04beff53f19ba558e1980260f9dd41.png

 

XElement root = XElement.Load(@"C:\source\repos\WindowsFormsApp1\WindowsFormsApp1\test.xml");
IEnumerable < XElement > games = root.Elements();


            foreach (var game in games)

            {
                try
                {
                    string pName = game.Element("Title").Value + " " + game.Element("Version").Value;
                    string pRom = System.IO.Path.GetFileNameWithoutExtension(game.Element("ApplicationPath").Value);
                    var clones = from nm in root.Elements("AdditionalApplication")
                                where (string)nm.Element("GameID") == game.Element("ID").Value
                                select nm;

                    if (clones.Any() == false)
                    {
                        MessageBox.Show("Parent: " + pName + " Rom: " + pRom);
                    }

                    try
                    {
                        foreach (var clone in clones)
                        {
                            string cName = clone.Element("Name").Value;
                            string cRom = System.IO.Path.GetFileNameWithoutExtension(clone.Element("ApplicationPath").Value);
                            cName = Regex.Replace(cName, @"Play ", "");
                            cName = Regex.Replace(cName, @" Version...", "");
                            MessageBox.Show("Parent: " + pName + " Rom: " + pRom + "\n"
                                + "Clone: " + cName + " Rom: " + cRom);
                        }
                    }

                    catch { }
                }

                catch { }

 

Share this post


Link to post
Share on other sites

Ok here is another upate to hopefully show what i'm trying to do.

Mame lists out all of its games files, and a bunch of stuff i dont care about in an XML file.

My frontend Launchbox stores all of its info in an xml file as well but does not have the same information tags so i can't do a straight comparison.

I want to be able to see what i have in my front end compared to that mame has.

 

I am able to go through both xml files and pull the data i need from each, as an individual variable. Now i need to store them in an array or list or something so i can go through and compare the individual files, and then display what is different or missing.

 

i need to get my individual data into this data grid after sorting, but i'm not sure the best way to store the individual data first.

i just typed this data in for an example... right now the button is the only thing working, and it just reads the xml files, and shows a message box of the individual variable.

ad01363f3fd670d5875e6d29498ed81a.png

Share this post


Link to post
Share on other sites

You just want to get all the stuff in a list?

 

Underneath: 

IEnumerable < XElement > games = root.Elements();

 

put

List<string> NameList = new List<string>();  
List<string> RomList = new List<string>();  

 

Then instead of 

MessageBox.Show("Parent: " + pName + " Rom: " + pRom);

Change that line to

NameList.Add(pName);  
RomList.Add(pRom);  

Then at the end your list will have all the values. 

 

 

Share this post


Link to post
Share on other sites

WOO HOOO

 

I'm getting there... this is all populated on its own from reading my xml file. Now i just have to compare the data to the other xml file, and have it display only the info that is different or missing. I'm excited... i have not programed anything in a really long time! Thanks Phenom, and Marsh for your guidance!

 

d4d52fdb8ce8bfb7afa2f64a2874ff07.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×