Я хотел бы создать новый упрощенный xml на основе существующего: (используя "simpleXml")
<?xml version="1.0" encoding="UTF-8"?>
<xls:XLS>
<xls:RouteInstructionsList>
<xls:RouteInstruction>
<xls:Instruction>Start</xls:Instruction>
</xls:RouteInstruction>
</xls:RouteInstructionsList>
<xls:RouteInstructionsList>
<xls:RouteInstruction>
<xls:Instruction>End</xls:Instruction>
</xls:RouteInstruction>
</xls:RouteInstructionsList>
</xls:XLS>
Поскольку в тегах элемента всегда есть двоеточия, он будет связываться с "simpleXml"", Я попытался использовать следующее решение -> ссылка .
Как мне создать новый xml с такой структурой:
<main>
<instruction>Start</instruction>
<instruction>End</instruction>
</main>
the" инструкция-элемент"получает свое содержимое от прежнего" xls: Instruction-element ".
Вот обновленный код: Но, к сожалению, он никогда не проходит через:
$source = "route.xml";
$xmlstr = file_get_contents($source);
$xml = @simplexml_load_string($xmlstr);
$new_xml = simplexml_load_string('<main/>');
foreach($xml->children() as $child){
print_r("xml_has_childs");
$new_xml->addChild('instruction', $child->RouteInstruction->Instruction);
}
echo $new_xml->asXML();
сообщения об ошибке нет,если я оставлю "@" ...