I have a sitemap with many urls. Something like:
<url>
<loc>
http://site.com/
</loc>
<priority>
0.50
</priority>
<changefreq>
daily
</changefreq>
<lastmod>
2011-07-27T06:58:53+00:00
</lastmod>
</url>
<url>
<loc>
http://site.com/link
etc etc....
I need to get all the links in the sitemap, nothing else.
I've tried:
$links = file('sitemap.xml', FILE_IGNORE_NEW_LINES);
foreach($links as $link) {
echo $link;
}
Now that echos all the links and leaves all the <loc>, <priority>
etc etc out but it still includes the change frequency, lastmod
etc etc....
So the output looks like this:
http://site.com/ 11 0.50 12 daily 13 2011-07-27T06:58:53+00:00 14 15 16 http://site.com/page.html 17 0.40 18 daily 19 2011-07-
and so on....
I need to just get the links and put the into an array. Any ideas?
Thank you.
EDIT:
Here is the code I'm using:
$urls = array();
$xml='sitemap.xml';
$DomDocument = new DOMDocument();
$DomDocument->preserveWhiteSpace = false;
$DomDocument->loadXML("$xml"); // $DOMDocument->load('filename.xml');
$DomNodeList = $DomDocument->getElementsByTagName('from');
foreach($DomNodeList as $url) {
$urls[] = $url->nodeValue;
}
//display it
echo "<pre>";
print_r($urls);
echo "</pre>";
Which returns the error: Warning: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity, line: 1
So i tried to test if it can even load the xml: I changed the xml file name to an invalid one ($xml='sit___emap.xml';
)
I should of got an error saying it couldn't open the file, but instead it came up with the same error as before, with the correct filename set. So i don't think its the sitemap.