I'm trying to read an XML file that I created. I'm using this code, but getting nothing out except 'the file was loaded successfully'. I've tried xpath and many others, but it just doesn't output. It is possible there is something wrong with my XML because I created the file by hand and I've never made an XML file before.
Ultimately, my goal is to be able to read an extension attribute and get the description, class, and icon.
<?php
if(!$xml = simplexml_load_file('formats.xml')) {
echo 'the file was loaded successfully';
print_r($xml);
}
else {
echo 'the file was not loaded';
}
?>
Here is the XML:
<?xml version="1.0"?>
<group class="doc" icon="./.images/doc.png" />
<type extension="doc" description="Legacy Word Document" />
<type extension="docx" description="XML Word Document" />
<type extension="ppt" description="Legacy PowerPoint" />
<type extension="pptx" description="XML PowerPoint" />
<type extension="pps" description="Legacy PowerPoint Show" />
<type extension="ppsx" description="XML PowerPoint Show" />
<type extension="docm" description="Macro Enabled Word Document" />
<type extension="dot" description="Legacy Word Template" />
<type extension="dotx" description="XML Word Template" />
<type extension="dotm" description="Macro Enabled Word Template" />
<type extension="log" description="A Log File" />
<type extension="msg" description="A Message File" />
<type extension="odt" description="OpenOffice Document" />
<type extension="pages" description="Apple Pages Document" />
<type extension="rtf" description="Rich Text Format" />
<type extension="tex" description="LaTeX Document" />
<type extension="wpd" description="Word Perfect Document" />
<type extension="ini" description="Settings File" />
<type extension="cfg" description="Config File" />
<type extension="conf" description="Config File" />
<type extension="nfo" description="Information File" />
<type extension="inf" description="Autorun File" />
<type extension="wps" description="Works Document" />
</group>
<group class="video" icon="./.images/video.png" />
<type extension="asf" description="Advanced Streaming Format" />
<type extension="asx" description="Windows Media Playlist" />
<type extension="avi" description="Audio-Video Interleave" />
<type extension="flv" description="Flash Player Video" />
<type extension="mkv" description="Matroska Video" />
<type extension="mov" description="Apple Movie" />
<type extension="mp4" description="MPEG 4 Video" />
<type extension="mpg" description="MPEG Video" />
<type extension="rm" description="RealMedia Video" />
<type extension="srt" description="Subtitles File" />
<type extension="swf" description="Flash Animation" />
<type extension="vob" description="DVD Video File" />
<type extension="wmv" description="Windows Media Video" />
<type extension="mpeg" description="Motion Picture Experts Video" />
</group>
<group>contains other element it should not be self-enclosing (/>at the end of opening tag)!$xml, which means it actually failed, owing the the invalid XML mentioned previously.libxml_get_errors()to see what SimpleXML is complaining about.