M
M
Makfroy2020-09-28 12:19:32
PHP
Makfroy, 2020-09-28 12:19:32

What is my mistake (parser)?

Hello, I'm trying to parse an xml file:

<?xml version="1.0" encoding="utf-8" ?> 
<xmlDoc>
<document quantity="1">
<reader>
  <entry>AB:ГОРОДСКОЙ ЧИТАТЕЛЬ</entry> 
  <entry>AA:5502d0933967dc713dea44699088b0cf</entry> 
  </reader>
<list>
  <entry codePlace="B001" place="Библиотека" total="1" /> 
  </list>
  </document>
  </xmlDoc>


Here is a php script:

<?php

     error_reporting(E_ALL);
     ini_set('display_errors', 'on');

     $xml = simplexml_load_file('index.xml');

     foreach ($xml->reader->entry as $entry) {
         echo $entry . '<br>';
     }


However, it gives an error:
Warning: Invalid argument supplied for foreach() in (path) on line 8

What did I do wrong in this script? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Never Ever, 2020-09-28
@4Geka

foreach ($xml->document->reader->entry as $entry) {
    echo $entry."\n" ;
}

$xml->reader->entryyou accessed an empty value and as a result an error in the future, just check what you pass to the print_r / var_dump loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question