I'm trying to get all xml-files from a folder, which works fine with this code i found on SO here:
$files = glob("folder/*xml");
if (is_array($files)) {
foreach($files as $filename) {
$xml_file = file_get_contents($filename, FILE_TEXT);
// and proceed with your code
}
}
Now I'm trying to get several content out of each xml-file.
By using this after the "// and proceed with your code" part
echo $xml_file.'<br /><br />';
I get the whole content of each file.
But I only want to retrieve several elements and attributes.
The xml-files i'm using are openimmo-based.The structure of these xml-files looks like this (excerpt):
<openimmo>
<anbieter>
<anbieternr>12345</anbieternr>
<firma>company name</firma>
<immobilie>
<objektkategorie>
<objektart>
<haus haustyp="DOPPELHAUSHAELFTE"/>
</objektart>
</objektkategorie>
<geo>
<plz>12345</plz>
</geo>
</immobilie>
</anbieter>
</openimmo>
I use another script, where a singe xml-file gets parsed and i can retrieve it's content like this:
echo 'Zip-Code: '.$user->immobilie->geo->plz.'<br />';
But how can I get the different contents of elements like geo->plz" or the attributes like <haus haustyp="DOPPELHAUSHAELFTE"/> by looping through each file of the given folder?