Pourriez vous m'aider?
Voilà je vous explique le problème, j'ai une vente avec plusieurs lots
J'ai repris un programme ou il y a une fonction qui avec un tableau associatif php génère un xml
Code : Tout sélectionner
function array_to_xml($array, &$xml) {
foreach ($array as $key => $value) {
if (is_array($value)) {
if (!is_numeric($key)) {
$subnode = $xml->addChild("$key");
array_to_xml($value, $subnode);
} else {
array_to_xml($value, $xml);
}
} else {
$value = htmlspecialchars($value);
$key = htmlspecialchars($key);
$xml->addChild("$key", "$value");
}
}
}Code : Tout sélectionner
"lots" => array:3 [▼
0 => array:34 [▶]
1 => array:34 [▶]
2 => array:34 [▶]Actuellement le tableau est construit comme cela :
Code : Tout sélectionner
foreach ($lots as $lot) { // pour chaque lot
if (isset($lot['MandatVente']) && $lot['MandatVente'] === $mandats[$i]->getId()) {
if (!isset($tab[$mandats[$i]->getVendeur()->getId()]['lots'])) {
$tab[$mandats[$i]->getVendeur()->getId()]['lots'] = [];
}
array_shift($lot);// j'enlève le lot je l'ai affecté à une vente
array_push($tab[$mandats[$i]->getVendeur()->getId()]['lots'], $lot); // j'ajoute le lot
}
}J'ai pensé sinon dans le code à faire cela, ou je dirais directement si tu vois la balise <idlot> alors tu m'ajoutes <lot> avant et pour la fermer j'utiliserais la dernière balise entre chaque lot, mais le str_replace transforme le xml en chaine de cractères auriez vous un moyen?
Code : Tout sélectionner
$xml_data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><root></root>');
array_to_xml($tabSV, $xml_data);
$xml = $xml_data->asXML();
$xml = str_replace("<IdLot>","<lot><IdLot>", $xml);