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 7644195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:37:34+00:00 2026-05-31T09:37:34+00:00

I have this piece of code that takes my xml and puts it into

  • 0

I have this piece of code that takes my xml and puts it into an array, I did a print_r of it and got this…

SimpleXMLElement Object ( [status] => SUCCESS [items] => SimpleXMLElement Object ( [item] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 1_ ) [id] => 1 [name] => Product 3 [price] => 20.00 [qty] => SimpleXMLElement Object ( ) [option] => SimpleXMLElement Object ( ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 3_ ) [id] => 3 [name] => Test Fin [price] => 30.00 [qty] => SimpleXMLElement Object ( ) [option] => SimpleXMLElement Object ( ) ) ) ) [amount] => 50 )

I am trying to echo out the amount, but nothing I try is working, I am new to xml and dont really know how to use it. if anyone can put me in the right direction, I would really appropriate it.

I’ve tried this…

echo $xml['amount'];

oh and here is my code…

$xml = simplexml_load_string($cartArray);
    if($xml->nodename){
        echo "the node exists";
    }
    $code = $xml->someNode;
    $message = $xml->someOtherNode;

Thanks,

  • J

PS – XML CODE

public function getCartItems() {
    $xml = "<?xml version='1.0'?>\n";
    $xml .= "<cart>\n";
    if(strlen($_SESSION["items"])==0) {
        $xml .= "<status>ERR</status>\n";
        $xml .= "<message>Cart is empty</message>\n";
    }
    else {
        $xml .= "<status>SUCCESS</status>\n";
        $xml .= "<items>\n";
        $total = 0;
        $this->itemArr = unserialize($_SESSION["items"]);
        foreach ($this->itemArr as $item) {
            $xml .= "<item id=\"".$item["id"] . '_' .$item["option"] ."\">\n";
            $xml .= "<id>".$item["id"]."</id>\n";
            $xml .= "<name>".$item["name"]."</name>\n";
            $xml .= "<price>".$item["price"]."</price>\n";
            $xml .= "<qty>".$item["qty"]."</qty>\n";
            $xml .= "<option>".$item["option"]."</option>\n";
            $xml .= "</item>\n";
            $total += ($item["price"]);
        }
        $xml .= "</items>\n";
        $xml .= "<amount>".$total."</amount>\n";
    }
    $xml .= "</cart>\n";
    return $xml;
}
  • 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-31T09:37:36+00:00Added an answer on May 31, 2026 at 9:37 am
    <?php
    
    $xml = "<?xml version='1.0'?>";
        $xml .= "<cart>\n";
    
            $xml .= "<status>SUCCESS</status>";
            $xml .= "<items>";
                $xml .= "<item ids='10'>";
                $xml .= "<id>20</id>";
                $xml .= "<name>ball</name>";
                $xml .= "<price>$50</price>\n";
                $xml .= "<qty>500</qty>\n";
                $xml .= "<option>color</option>\n";
                $xml .= "</item>\n";
                $xml .= "</items>\n";
                $xml .= "<amount>555</amount>\n";
    
            $xml .= "</cart>\n";
            $xmls = simplexml_load_string($xml);
            $var = $xmls->items->item;
            print_r($var->name);
     ?>
    

    It will return

    SimpleXMLElement Object
    (
        [0] => ball
    )
    

    I think, you didnt get name value because the attribute name of item and element of XML was same. so i changed

    $xml .= "<item id='10'>";
    

    to

    $xml .= "<item ids='10'>";
    

    and its done. Enjoy 🙂

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

Sidebar

Related Questions

I have this small piece of code that basically takes a list and runs
I have a piece of code that the ARC converter turned into this... //
I have got a piece of code, that should countdown some number (in this
I have one piece of Cocoa code I wrote that takes in an XML
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this piece of code that works fine in subsonic 2.2, I migrated
I have this piece of code that is giving me trouble. I know all
Assume that I have this piece of code: @interface Foo : NSObject { Bar
I have this program that should execute a piece of code base on the
I have a piece of code that look similar to this: <xsl:choose> <xsl:when test=some_test>

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.