Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 635767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:26:28+00:00 2026-05-13T20:26:28+00:00

I´m working on a paymentsolution and need some help with the PHP. I´m doing

  • 0

I´m working on a paymentsolution and need some help with the PHP. I´m doing a HTTPRequest and in response I will get some XML. The XML Could look like this:

<?xml version="1.0" encoding="utf-8" ?>
<payer>
    <purchase_list>
            <freeform_purchase>
                <line_number>1</line_number>
                <description>description</description>
                <price_including_vat>12</price_including_vat>
                <vat_percentage>
                    15
                </vat_percentage>
                <quantity>10</quantity>
            </freeform_purchase>
    </purchase_list>
    <payment_urls>
        <auth_url>authurl</auth_url>
        <settle_url>settleurl</settle_url>
    </payment_urls>
</payer>

Basically what I want to do is to get the content from the tags and save them in strings.

I tried this:

$order = '<?xml version="1.0" encoding="utf-8" ?>
<payer>
    <purchase_list>
            <freeform_purchase>
                <line_number>1</line_number>
                <description>description</description>
                <price_including_vat>12</price_including_vat>
                <vat_percentage>
                    15
                </vat_percentage>
                <quantity>10</quantity>
            </freeform_purchase>
    </purchase_list>
    <payment_urls>
        <auth_url>authurl</auth_url>
        <settle_url>settleurl</settle_url>
    </payment_urls>
</payer>';

$orderXML = new DOMDocument();
$orderXML->load($order);

$payerXML = $orderXML->getElementsByTagName( 'payer' );
$purchase_listXML = $orderXML->getElementsByTagName( 'purchase_list' );
$freeform_purchaseXML = $orderXML->getElementsByTagName( 'freeform_purchase' );
$linenumberXML = $orderXML->getElementsByTagName( 'line_number' );
$descriptionXML = $orderXML->getElementsByTagName( 'description' );
$price_inc_vatXML = $orderXML->getElementsByTagName( 'price_including_vat' );
$vat_percentageXML = $orderXML->getElementsByTagName( 'vat_percentage' );
$quantityXML = $orderXML->getElementsByTagName( 'quantity' );
$settle_urlXML = $orderXML->getElementsByTagName( 'settle_url' );
$auth_urlXML = $orderXML->getElementsByTagName( 'auth_url' );

$theLineNumber = $linenumberXML->item(0)->nodeValue;
$theValue = $descriptionXML->item(0)->nodeValue;
$freeform_price = $price_inc_vatXML->item(0)->nodeValue;
$freeform_vat = $vat_percentageXML->item(0)->nodeValue;
$freeform_quantity = $quantityXML->item(0)->nodeValue;

$Settle_url = $settle_urlXML->item(0)->nodeValue;
$Auth_url = $auth_urlXML->item(0)->nodeValue;

echo 'thLineNumber - ' . $theLineNumber;
echo $theValue;
echo $freeform_price;
echo $freeform_vat;
echo $freeform_quantity;
echo $Settle_url;
echo $Auth_url;

But obviously there is something wrong since it won´t echo anything.. Suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:26:29+00:00Added an answer on May 13, 2026 at 8:26 pm

    If you are only trying to read some data from an XML string, the simplest way would probably be to use SimpleXML, and not DOM — DOM is well suited when it comes to writing XML, but for reading, SimpleXML is much easy to work with.

    For instance, you could use something like this as a starting point :

    Note I used the simplexml_load_string function to load the XML string.

    $string = <<<STR
    <?xml version="1.0" encoding="utf-8" ?>
    <payer>
        <purchase_list>
                <freeform_purchase>
                    <line_number>1</line_number>
                    <description>description</description>
                    <price_including_vat>12</price_including_vat>
                    <vat_percentage>
                        15
                    </vat_percentage>
                    <quantity>10</quantity>
                </freeform_purchase>
        </purchase_list>
        <payment_urls>
            <auth_url>authurl</auth_url>
            <settle_url>settleurl</settle_url>
        </payment_urls>
    </payer>
    STR;
    
    $xml = simplexml_load_string($string);
    
    echo intval($xml->purchase_list->freeform_purchase->price_including_vat) . '<br />';
    echo (string)$xml->payment_urls->auth_url . '<br />';
    

    Which would give you the following output :

    12
    authurl
    

    Basically, with SimpleXML, the XML tree is available as an object — the root node of the XML not being present in the tree, as it’s the root ; which is why I didn’t have to include payer to access the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 311k
  • Answers 311k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Processes aren't Unicode or non-Unicode, they're just processes. The Unicode/non-Unicode… May 13, 2026 at 10:22 pm
  • Editorial Team
    Editorial Team added an answer Here's some extension methods I use to do what you… May 13, 2026 at 10:22 pm
  • Editorial Team
    Editorial Team added an answer You're pretty close, actually! if (obj instanceof Integer) put(key,integerval); if… May 13, 2026 at 10:22 pm

Related Questions

I´m working on a project, in Visual Studio 2008, which DLL currently surpasses 20
I´m working on a project that basically will show some data collected from hardware
I´m working on a huge project at my work. We have about 200 database
The project I´m working on needs to auth its users against AD, and as
I´m working in a jQuery pluging, and i have one error, i want modify

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.