0

This is what my XML looks like

<?xml version="1.0" encoding="UTF-8"?>
  <item>
    <date>May 2013</date>
    <html>http://www.link.to/html.html</html>
  </item>

I do this in the PHP and it kind of works

$file = '../modules/xml/nl-archive.xml';
$xml = simplexml_load_file($file);
$string = '';
foreach($xml as $item){
    $string .= '<a href="'.$item->html .'" ><li>'.$item->date .'</li></a>';
}

Just trying to get the contents of the date tag and html tag to show up for each of the item tags. Been googling and tinkering, can't get it right. What am I doing wrong?

1 Answer 1

3

Try changing your XML to have a root with children like:

<?xml version="1.0" encoding="UTF-8"?>
<items>
    <item>
        <date>May 2013</date>
        <html>http://www.link.to/html.html</html>
    </item>
</items>

Php is just fine as you have it.

Sign up to request clarification or add additional context in comments.

1 Comment

Ohhhh! I know that simplexml_load_file() usually just loads up the root tag so I thought it wouldn't matter if I had a root or not. Makes total sense now. thanks so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.