I’m trying to parse the contents of an remote XML file into MySQL, so I can put these contents in my database.
I’m not fimiliar with XML at all, so sorry if I’ll be asking stupid questions.
I have a site: http://www.hodexer.nl/hodex/uva/hodexDirectory.xml. For every hodexRecourse, I want to get the programID, and visit the URL stored in hodexResourceURL, and from that XML file, I want every programName and programSummary and store these into the database as well.
I know the global set up I should use, but I’m not getting very far. So far I have this:
$xmlstr = simpleXML_load_file('http://www.hodexer.nl/hodex/uva/hodexDirectory.xml');
if ($xmlstr === FALSE) {
show_404();
}
else {
$xml = new SimpleXMLElement($xmlstr, NULL, TRUE);
foreach ($xml->hodexResource as $temp) {
echo $temp->programID;
}
The echo is just for debugging purpouses. I get the following error: String could not be parsed as XML.
I hope you can help me out!
the function simpleXML_load_file returns an SimpleXmlObject, is not necessary to call the constructor, you can see this in http://www.php.net/manual/es/class.simplexmlelement.php
Try this code: