Mam do przygotowania plik XML o następującej strukturze:
<?xml version="1.0" encoding="utf-8"?> <import> <offers> <offer> <sku>123</sku> <product-id>0000000000000</product-id> <product-id-type>EAN</product-id-type> <price>170.1</price> <quantity>2</quantity> <state>11</state> <logistic-class>1</logistic-class> <leadtime-to-ship>2</leadtime-to-ship> </offer> <offer> <sku>123</sku> <product-id>0000000000000</product-id> <product-id-type>EAN</product-id-type> <price>170.1</price> <quantity>2</quantity> <state>11</state> <logistic-class>1</logistic-class> <leadtime-to-ship>2</leadtime-to-ship> </offer> </offers> </import>
Do utworzenia pliku używam SimpleXML. Problemem jest stworzenie jednocześnie tagu <import> oraz <offers>.
Gdy próbuję zrobić to w ten sposób:
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><import></import>'); $xml = $xml->addChild('offers'); $shopitem = $xml->addChild('offer'); /*Tutaj dodaję pozostałe tagi*/
Otrzymuję XML w postaci:
<offers> <offer> <sku>123</sku> <product-id>0000000000000</product-id> <product-id-type>EAN</product-id-type> <price>170.1</price> <quantity>2</quantity> <state>11</state> <logistic-class>1</logistic-class> <leadtime-to-ship>2</leadtime-to-ship> </offer> <offer> <sku>123</sku> <product-id>0000000000000</product-id> <product-id-type>EAN</product-id-type> <price>170.1</price> <quantity>2</quantity> <state>11</state> <logistic-class>1</logistic-class> <leadtime-to-ship>2</leadtime-to-ship> </offer> </offers>
Ginie mi w tym przypadku zewnętrzny tag <import>
Próbowałem również użyć tego sposobu:
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><import><offers></offers></import>');
Bez skutku, otrzymuję strukturę w tej postaci:
<?xml version="1.0" encoding="utf-8"?> <import> <offers/> <offer> <sku>123</sku> <product-id>0000000000000</product-id> <product-id-type>EAN</product-id-type> <price>170.1</price> <quantity>2</quantity> <state>11</state> <logistic-class>1</logistic-class> <leadtime-to-ship>2</leadtime-to-ship> </offer> </import>
Jakieś pomysły?