XML Parse - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of XML Parse.php
- <?php
- $resp='{
- "Id": "b7676489-7f0b-495c-a80f-74437b95dd6e",
- "Status": "OK",
- "ProviderName": "API Explorer",
- "DateTimeUTC": "\/Date(1633543239638)\/",
- "Invoices": [
- {
- "Type": "ACCREC",
- "InvoiceID": "07f4e2b5-7693-4506-b1b9-585d2b1ce316",
- "InvoiceNumber": "INV-0042",
- "Reference": "Website Design",
- "Prepayments": [],
- "Overpayments": [],
- "AmountDue": 40.00,
- "AmountPaid": 0.00,
- "SentToContact": false,
- "CurrencyRate": 1.0000000000,
- "IsDiscounted": false,
- "HasErrors": false,
- "Contact": {
- "ContactID": "ea5f94be-d51c-4775-b8cc-fe70539aa915",
- "ContactNumber": "9d788d880f299b1eaaa4def1066afc04883126eabbd99574d6",
- "ContactStatus": "ACTIVE",
- "Name": "Shawn Fernandes",
- "FirstName": "Shawn",
- "LastName": "Fernandes",
- "EmailAddress": "[email protected]",
- "Addresses": [
- {
- "AddressType": "POBOX"
- },
- {
- "AddressType": "STREET"
- }
- ],
- "Phones": [
- {
- "PhoneType": "DEFAULT"
- },
- {
- "PhoneType": "DDI"
- },
- {
- "PhoneType": "FAX"
- },
- {
- "PhoneType": "MOBILE"
- }
- ],
- "UpdatedDateUTC": "\/Date(1633052796037+0000)\/",
- "ContactGroups": [],
- "IsSupplier": false,
- "IsCustomer": true,
- "SalesTrackingCategories": [],
- "PurchasesTrackingCategories": [],
- "ContactPersons": [],
- "HasValidationErrors": false
- },
- "DateString": "2019-03-11T00:00:00",
- "Date": "\/Date(1552262400000+0000)\/",
- "DueDateString": "2018-12-10T00:00:00",
- "DueDate": "\/Date(1544400000000+0000)\/",
- "BrandingThemeID": "324587a9-7eed-46c0-ad64-fa941a1b5b3e",
- "Status": "AUTHORISED",
- "LineAmountTypes": "Exclusive",
- "LineItems": [
- {
- "Description": "Acme Tires",
- "UnitAmount": 20.00,
- "TaxType": "NONE",
- "TaxAmount": 0.00,
- "LineAmount": 40.00,
- "AccountCode": "220",
- "Tracking": [],
- "Quantity": 2.0000,
- "LineItemID": "6ab5aae1-d5ee-4de9-8150-54d13c4a3977",
- "ValidationErrors": []
- }
- ],
- "SubTotal": 40.00,
- "TotalTax": 0.00,
- "Total": 40.00,
- "UpdatedDateUTC": "\/Date(1633543239193+0000)\/",
- "CurrencyCode": "USD"
- }
- ]
- }';
- //$resp=json_encode($resp);
- //var_dump($resp);
- $json_resp2 = json_decode($resp,true);
- //Parse invoice id from response
- $invoice_id= $json_resp2['Invoices'][0]['InvoiceID'];
- echo $invoice_id."\n";
- echo "ln 3 \n";
- echo "ln 4 \n";
- $resp2='<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Id>84e042a2-acf0-4d18-ac53-8ee15f7907b2</Id> <Status>OK</Status> <ProviderName>Test OAuth NMI</ProviderName> <DateTimeUTC>2021-10-06T21:37:35.6205401Z</DateTimeUTC> <Invoices> <Invoice> <Contact> <ContactID>ea5f94be-d51c-4775-b8cc-fe70539aa915</ContactID> <ContactNumber>9d788d880f299b1eaaa4def1066afc04883126eabbd99574d6</ContactNumber> <ContactStatus>ACTIVE</ContactStatus> <Name>Shawn Fernandes</Name> <FirstName>Shawn</FirstName> <LastName>Fernandes</LastName> <EmailAddress>[email protected]</EmailAddress> <Addresses> <Address> <AddressType>POBOX</AddressType> </Address> <Address> <AddressType>STREET</AddressType> </Address> </Addresses> <Phones> <Phone> <PhoneType>DEFAULT</PhoneType> </Phone> <Phone> <PhoneType>DDI</PhoneType> </Phone> <Phone> <PhoneType>FAX</PhoneType> </Phone> <Phone> <PhoneType>MOBILE</PhoneType> </Phone> </Phones> <UpdatedDateUTC>2021-10-01T01:46:36.037</UpdatedDateUTC> <IsSupplier>false</IsSupplier> <IsCustomer>true</IsCustomer> </Contact> <Date>2021-10-06T00:00:00</Date> <DueDate>2021-10-16T00:00:00</DueDate> <BrandingThemeID>324587a9-7eed-46c0-ad64-fa941a1b5b3e</BrandingThemeID> <Status>AUTHORISED</Status> <LineAmountTypes>Exclusive</LineAmountTypes> <LineItems> <LineItem> <Description>Test Order NMI Gateway</Description> <UnitAmount>93.00</UnitAmount> <TaxType>NONE</TaxType> <TaxAmount>0.00</TaxAmount> <LineAmount>93.00</LineAmount> <AccountCode>220</AccountCode> <Quantity>1.0000</Quantity> <LineItemID>9eff054e-4dd7-4eac-9acd-e3d5ce3277b1</LineItemID> </LineItem> </LineItems> <SubTotal>93.00</SubTotal> <TotalTax>0.00</TotalTax> <Total>93.00</Total> <UpdatedDateUTC>2021-10-06T21:37:35.543</UpdatedDateUTC> <CurrencyCode>USD</CurrencyCode> <Type>ACCREC</Type> <InvoiceID>19f96b3c-05e5-4d2b-88f3-537ee6625931</InvoiceID> <InvoiceNumber>INV-0048</InvoiceNumber> <Reference>Website Design</Reference> <AmountDue>93.00</AmountDue> <AmountPaid>0.00</AmountPaid> <SentToContact>false</SentToContact> <CurrencyRate>1.0000000000</CurrencyRate> <HasErrors>false</HasErrors> </Invoice> </Invoices> </Response>';
- $resp2 = new SimpleXMLElement($resp2);
- var_dump((array)$resp2);
- echo " ln br9 \n";
- echo "ln br10 \n";
- $val=(array)$resp2;
- var_dump($val['Invoices']);
- echo " ln br7 \n";
- echo "ln br 8 \n";
- $resp2=json_encode($resp2);
- var_dump($resp2);
- echo " ln br5 \n";
- echo "ln br 6 \n";
- $json_resp22 = json_decode($resp2,true);
- var_dump($json_resp22);
- echo " ln br1 \n";
- echo "ln br 2 \n";
- //Parse invoice id from response
- $invoice_id2= $json_resp22['Invoices']['Invoice']['InvoiceID'];
- echo var_dump($invoice_id2);