php - Adding Child element to XML -



php - Adding Child element to XML -

i have xml of form

$xml=<<<eod <?xml version="1.0" encoding="utf-8"?> <completesalerequest xmlns="urn:ebay:apis:eblbasecomponents"> <requestercredentials> <ebayauthtoken>auth_token_value</ebayauthtoken> </requestercredentials> <itemid>itemidvalue</itemid> <transactionid>transactionidvalue</transactionid> <shipped>1</shipped> <paid>1</paid> <shipment> <shipmenttrackingdetails> <shipmenttrackingnumber>$trackingno</shipmenttrackingnumber> <shippingcarrierused>ups</shippingcarrierused> </shipmenttrackingdetails> <shippedtime>2014-09-30 12:41:59.202303</shippedtime> </shipment> <errorlanguage> string </errorlanguage> eod;

i want append more shipmenttrackingdetails portion using php, need resulting xml this:

$xml=<<<eod <?xml version="1.0" encoding="utf-8"?> <completesalerequest xmlns="urn:ebay:apis:eblbasecomponents"> <requestercredentials> <ebayauthtoken>auth_token_value</ebayauthtoken> </requestercredentials> <itemid>itemidvalue</itemid> <transactionid>transactionidvalue</transactionid> <shipped>1</shipped> <paid>1</paid> <shipment> <shipmenttrackingdetails> <shipmenttrackingnumber>$trackingno</shipmenttrackingnumber> <shippingcarrierused>ups</shippingcarrierused> </shipmenttrackingdetails> <shipmenttrackingdetails> <shipmenttrackingnumber>$trackingno2</shipmenttrackingnumber> <shippingcarrierused>ups</shippingcarrierused> </shipmenttrackingdetails> <shipmenttrackingdetails> <shipmenttrackingnumber>$trackingno3</shipmenttrackingnumber> <shippingcarrierused>ups</shippingcarrierused> </shipmenttrackingdetails> <shippedtime>2014-09-30 12:41:59.202303</shippedtime> </shipment> <errorlanguage> string </errorlanguage> eod;

php source:

$sxe = new simplexmlelement($xml); $track = $sxe->addchild('shipmenttrackingdetails'); $track->addchild("shipmenttrackingnumber", "9876"); $track->addchild("shippingcarrierused", "usps");

i not getting how using php. please help in getting working.

thanks!

i got it, dynamic part be:

$sxe = new simplexmlelement($xml); $trackingdetails = $sxe->shipment->addchild('shipmenttrackingdetails'); $trackingdetails->addchild("shipmenttrackingnumber", $trackingmore); $trackingdetails->addchild("shippingcarrierused", "ups"); $sxe->asxml("tracking.xml"); $xml1 = $sxe->savexml();

where $xml original xml want add together new child.

php xml

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -