A
A
Alexander Babiy2018-02-02 15:33:07
PHP
Alexander Babiy, 2018-02-02 15:33:07

xml has a base element and child elements. How to refer to children if they have the same name?

Hello!
The question is in the topic, but the point is that you need to copy the element and element attributes from one file to another. So - element 1 is created, attributes are read and added, element 2 is created, attributes are read, but since there are 2 such elements, they are copied from the first. Elements with the same names and attributes are obtained at the output.
How to iterate over this assoc. array if the keys are the same and refer to the one you need? By 3, 4, 5...?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2018-02-02
@flx12

$catalog = new SimpleXMLElement(file_get_contents($file));
    foreach($catalog->stores->store as $arStore){
        $name = (string)$arStore['name'];
    }

xml structure is like this
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <stores>
    <store uid="111" name="444"/>
    <store uid="222" name="555"/>
    <store uid="333" name="666"/>
  </stores>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question