C
C
Camokat12016-01-26 22:39:02
PHP
Camokat1, 2016-01-26 22:39:02

Problem with loops when parsing xml, what am I doing wrong?

I have an xml construct
< ?xml version="1.0" encoding="utf-8" ?>
< product prodID="28">
< pictures>
< picture>1< /picture>
< picture>2< /picture>
< picture >3< /picture>
</pictures>
< /product>
< product prodID="53">
< pictures>
< picture>1< /picture>
< picture>2< /picture>
< /pictures>
</product>
Thought parse it like this, but it doesn't come out
<?php
$xml = simplexml_load_file('1.xml');
foreach ($xml->product as $product) {
foreach ($xml->
product->pictures as $pictures) { echo $product[prodID];
echo $pictures->picture;
}
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
qnicolya, 2016-01-26
@qnicolya

I'm not sure for the purpose of parsing the document, but I think it's
worth writing instead
foreach ($product->pictures as $pictures)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question