Skrok
12-02-2010, 10:23
Hallo,
ich habe ein kleines Problem. Ich möchte einen Bestand abfragen und muss dafür folgende Struktur übermitteln:
<Products>
<Product>
<ProductID>xxx</ProductID>
</Product>
<Product>
<ProductID>xxx</ProductID>
</Product>
</Products>
Mein logisches Verständniss
$xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><Request></Request>");
$array = array("xxx","xxx");
$xml->AddChild("Products");
for($i=0;$i<2;$i++){
$xml->Products->AddChild("Product");
$xml->Products->Product->AddChild("ProductID",$array[$i]);
}
echo $xml->asXml();
mein XML ->
<?xml version="1.0" encoding="utf-8"?>
<Request>
<Products>
<Product>
<ProductID>6252881</ProductID>
<ProductID>6252881</ProductID>
</Product>
<Product/>
</Products>
</Request>
Irgendwie stehe ich gerade auf meinem Hirn oder so aber mir will nicht einfallen wo ich den Denkfehler drin habe.
*join*
$xml->Products->AddChild("Product")->AddChild("ProductID",$array[$i]);
Funktioniert!
ich habe ein kleines Problem. Ich möchte einen Bestand abfragen und muss dafür folgende Struktur übermitteln:
<Products>
<Product>
<ProductID>xxx</ProductID>
</Product>
<Product>
<ProductID>xxx</ProductID>
</Product>
</Products>
Mein logisches Verständniss
$xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><Request></Request>");
$array = array("xxx","xxx");
$xml->AddChild("Products");
for($i=0;$i<2;$i++){
$xml->Products->AddChild("Product");
$xml->Products->Product->AddChild("ProductID",$array[$i]);
}
echo $xml->asXml();
mein XML ->
<?xml version="1.0" encoding="utf-8"?>
<Request>
<Products>
<Product>
<ProductID>6252881</ProductID>
<ProductID>6252881</ProductID>
</Product>
<Product/>
</Products>
</Request>
Irgendwie stehe ich gerade auf meinem Hirn oder so aber mir will nicht einfallen wo ich den Denkfehler drin habe.
*join*
$xml->Products->AddChild("Product")->AddChild("ProductID",$array[$i]);
Funktioniert!
