Hi All,
I am trying to figure out a way to skip duplicate entries in an XML file. To be honest I haven’t worked with XML much at all and have no idea where to start.
I’ve went through the SimpleXML manual to make it as far as I have which is simply echoing out the elements in the XML object that are needed.
I am building this so I can take a flat db file from a program and put it into a MySQL so I can build a quick and simple way of manually adding songs to the search. What I will be placing into the MySQL database will be only a couple of a the attributes in the display node.
I really need to use both the Author and Title attributes to compare each song as I don’t want to remove every all but one song by the an author and some songs have been done and done again by different authors.
What I need to do is compare two
Here is an example of the XML content. There are currently 110,609 songs in the XML database.
<Song FilePath="C:\English Rap R&B\iTunes\iTunes Media\Music\JUELZ SANTANA\WHAT THE GAME BEEN MISSING\15 J.m4a" FileSize="7829897">
<Display Author="JUELZ SANTANA" Title="J" Album="WHAT THE GAME BEEN MISSING" Color="2324603" Cover="2" Tag="1" />
</Song>
<Song FilePath="C:\ALL MP3's\Music in Folders\DaveMathews Band\#41.mp3" FileSize="4802953">
<Display Author="DAVE MATTHEWS" Title="#41" Genre="Rock" Album="Crash" Year="2000" Color="3768206" Cover="2" Tag="1" />
</Song>
Here is my current PHP which displays the Author, Title, and Genre in my web browser. Including a count to count the number of songs which I will use later to say X amount of songs has been inserted into the database if a file is used rather than manually entering the information.
[php]
if (file_exists(‘music_db.xml’)) {
$xml = simplexml_load_file(‘music_db.xml’);
$x=1;
foreach($xml->children() as $song)
{
echo "<pre>";
foreach($song->children() as $child)
{
if(!empty( $child->attributes()->Author) && !empty($child->attributes()->Title) && !empty($child->attributes()->Genre) && !is_numeric((string)$child->attributes()->Title))
{
echo "Author:" . $child->attributes()->Author, "<br />";
echo "Title:" . $child->attributes()->Title, "<br />";
echo "Genre:" . $child->attributes()->Genre, "<br />";
echo $x;
$x++;
}
echo "</pre>";
}
}
foreach(libxml_get_errors() as $error)
{
echo “\t”, $error->message;
}
}
else {
exit(‘Failed to open music_db.xml.’);
}
[/php]