I am fairly new to programming with Python and I want to compare values of 2 XML-Files and adding the missing values from XML-File2 to XML-File1
Since I am fairly new I tried to google the basics and got used to the Elementtree Object, I know how to open a file and how to access single elements and traversing the tree. However I do not know how to compare 2 documents with each other.
What I need the script to do is take title and genre from file1, search for them in file2 then compare the child-elements of the active/current <MData> and if they match, add the additional data (that isn't present in file1) to file1. I don't know how to make a proper comparison though. My current guess is that I should add the missing elements to a final xml (see below) and compare the final xml with file2 instead.
At first I thought this was easy but the more I look into it the harder it feels to solve. Any help or any direction is appreciated since I don't really know where to start coding.
Here are the XML Files
File1
Since I am fairly new I tried to google the basics and got used to the Elementtree Object, I know how to open a file and how to access single elements and traversing the tree. However I do not know how to compare 2 documents with each other.
What I need the script to do is take title and genre from file1, search for them in file2 then compare the child-elements of the active/current <MData> and if they match, add the additional data (that isn't present in file1) to file1. I don't know how to make a proper comparison though. My current guess is that I should add the missing elements to a final xml (see below) and compare the final xml with file2 instead.
At first I thought this was easy but the more I look into it the harder it feels to solve. Any help or any direction is appreciated since I don't really know where to start coding.
Here are the XML Files
File1
<ROOT> <Meta> <Randominfo>Random</Randominfo> </Meta> <MovieList> <Movie> <Movieparameters> <Movieparameter genre="Action" Title="Matrix"> <Length>120 mins</Length> <Blu-Ray>Yes</Blu-Ray> <Available>No</Available> <LentTo>Mr Anderson</LentTo> </Movieparameter> </Movieparameters> <Storeparameter> <ID>0001</ID> </Storeparameter> </Movie> <Movie> <Movieparameters> <Movieparameter genre="Action" Title="Matrix Reloaded"> <Length>111 mins</Length> <Blu-Ray>Yes</Blu-Ray> <Available>No</Available> <LentTo>Carrie Ann Moss</LentTo> </Movieparameter> </Movieparameters> <Storeparameter> <ID>0005</ID> </Storeparameter> </Movie> <Movie> <Movieparameters> <Movieparameter genre="DogMovie" Title="Woofworld"> <Length>120 mins</Length> <Blu-Ray>no</Blu-Ray> <Available>No</Available> <LentTo>Mr Woofer</LentTo> </Movieparameter> </Movieparameters> <Storeparameter> <ID>0002</ID> </Storeparameter> </Movie> <Movie> <Movieparameters> <Movieparameter genre="Live Concert" Title="BORK"> <Length>30 mins</Length> <Blu-Ray>Yes</Blu-Ray> <Available>Yes</Available> <LentTo>None</LentTo></LentTo> </Movieparameter> </Movieparameters> <Storeparameter> <ID>0003</ID> </Storeparameter> </Movie> </MovieList> </ROOT>File2
<ArrayOfData> <Mdata> <MovieGenre>Action</MovieGenre> <MovieName>Matrix</MovieName> <IMDBID>0178544444</IMDBID> <Reseller>SmithAndSmith</Reseller> <Price>10 Eur</Price> <Length>120 mins</Length> <Blu-Ray>Yes</Blu-Ray> </Mdata> <Mdata> <MovieGenre>Action</MovieGenre> <MovieName>Matrix Reloaded</MovieName> <IMDBID>0178555555</IMDBID> <Reseller>SmithAndSmith</Reseller> <Price>12 Eur</Price> <Length>111 mins</Length> <Blu-Ray>Yes</Blu-Ray> </Mdata> <Mdata> <MovieGenre>DogMovie</MovieGenre> <MovieName>WoofWorld</MovieName> <IMDBID>09647852154</IMDBID> <Reseller>DogsAndDogs</Reseller> <Price>5 Eur</Price> <Length>120 mins</Length> <Blu-Ray>No</Blu-Ray> </Mdata> <MovieGenre>Live Concert</MovieGenre> <MovieName>BORK</MovieName> <IMDBID>1337852</IMDBID> <Reseller>DogsAndDogs</Reseller> <Price>5 Eur</Price> <Length>120 mins</Length> <Blu-Ray>Yes</Blu-Ray> <Mdata> </Mdata> </ArrayOfData>Final Result (What I want it to look like)
<ROOT> <Meta> <Randominfo>Random</Randominfo> </Meta> <MovieList> <Movie> <Movieparameters> <Movieparameter genre="Action" Title="Matrix"> <Length>120 mins</Length> <Blu-Ray>Yes</Blu-Ray> <Available>No</Available> <LentTo>Mr Anderson</LentTo> <IMDBID>0178544444</IMDBID> <Reseller>SmithAndSmith</Reseller> <Price>10 Eur</Price> </Movieparameter> </Movieparameters> <Storeparameter> <ID>0001</ID> </Storeparameter> </Movie> <Movie> <Movieparameters> <Movieparameter genre="Action" Title="Matrix Reloaded"> <Length>111 mins</Length> <Blu-Ray>Yes</Blu-Ray> <Available>No</Available> <LentTo>Carrie Ann Moss</LentTo> <IMDBID>0178555555</IMDBID> <Reseller>SmithAndSmith</Reseller> <Price>12 Eur</Price> </Movieparameter> </Movieparameters> <Storeparameter> <ID>0005</ID> </Storeparameter> </Movie> <Movie> <Movieparameters> <Movieparameter genre="DogMovie" Title="Woofworld"> <Length>120 mins</Length> <Blu-Ray>no</Blu-Ray> <Available>No</Available> <LentTo>Mr Woofer</LentTo> <IMDBID>09647852154</IMDBID> <Reseller>DogsAndDogs</Reseller> <Price>5 Eur</Price> </Movieparameter> </Movieparameters> <Storeparameter> <ID>0002</ID> </Storeparameter> </Movie> <Movie> <Movieparameters> <Movieparameter genre="Live Concert" Title="BORK"> <Length>30 mins</Length> <Blu-Ray>Yes</Blu-Ray> <Available>Yes</Available> <LentTo>None</LentTo></LentTo> <IMDBID>1337852</IMDBID> <Reseller>DogsAndDogs</Reseller> <Price>5 Eur</Price> </Movieparameter> </Movieparameters> <Storeparameter> <ID>0003</ID> </Storeparameter> </Movie> </MovieList> </ROOT>