nehme an, ich habe eine XML wie folgt aus:PHP: entfernen Knoten aus XML durch Attribut
<products>
<product id="1">
<name>aaa</name>
<producturl>aaa</producturl>
<bigimage>aaa</bigimage>
<description>aaa</description>
<price>aaa</price>
<categoryid1>aaa</categoryid1>
<instock>aaa</instock>
</product>
<product id="2">
<name>aaa</name>
<producturl>aaa</producturl>
<bigimage>aaa</bigimage>
<description>aaa</description>
<price>aaa</price>
<categoryid1>aaa</categoryid1>
<instock>aaa</instock>
</product>
</products>
und ich brauche in Abhängigkeit von der id-Attribut bestimmten Knoten zu löschen, wenn dieses Attribut in einem Array ist.
Ich habe verschiedene Möglichkeiten ausprobiert, aber das XML wird immer als das Original ausgegeben!
Mein Code so weit:
<?php header("Content-type: text/xml");
$url="http://www.aaa.it/aaa.xml";
$url=file_get_contents($url);
$array=array("1","4","5");
$doc=new SimpleXMLElement($url);
foreach($doc->product as $product){
if(!in_array($product['id'],$array)){
$dom=dom_import_simplexml($product);
$dom->parentNode->removeChild($dom);
// unset($doc->product->$product);
}
}
echo $doc->asXml(); ?>
Vielen Dank alle.
Ich habe nicht, dass die Verlängerung (XSLTProcessor) – Zak
Sie können die [Erweiterung] aktivieren (http://stackoverflow.com/questions/7930726/fatal-error-class-xsltprocessor-not-found) in Ihre INI-Datei. – Parfait