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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:09:29+00:00 2026-05-27T06:09:29+00:00

I am querying an xml file with php like this : public function trackOrderAction()

  • 0

I am querying an xml file with php like this :

 public function trackOrderAction()
    {        
        $request = Mage::getResourceModel( 'order/request' );
        $request->setOrder($this->getRequest()->getParam('increment_id'));
        $response = $request->submit(true);
        $xml = simplexml_load_string($response);
        $items = count($xml->OrderItems->OrderItem);
     }

The xml is not ready immediately so if people try to use the function before it is ready there is an error because it is trying to get the property of a non-object. My question is what is the proper way to check the xml response to see if there is anything and stop the function if there is not?

I tried something simple like

    if (empty($xml)){
      die();
    }  else {
              $items = count($xml->OrderItems->OrderItem);
            }

But this does not help. Any ideas on how to check to see if the xml loaded?

  • 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-27T06:09:30+00:00Added an answer on May 27, 2026 at 6:09 am

    From http://us.php.net/manual/en/function.simplexml-load-string.php

    Returns an object of class SimpleXMLElement with properties containing
    the data held within the xml document. On errors, it will return
    FALSE.

     public function trackOrderAction()
        {        
            $request = Mage::getResourceModel( 'order/request' );
            $request->setOrder($this->getRequest()->getParam('increment_id'));
            $response = $request->submit(true);
            $xml = simplexml_load_string($response);
            if ( !$xml ) {
                return false;
            }
            $items = count($xml->OrderItems->OrderItem);
         }
    

    It will return false if there was an error. So fail right away if simplexml_load_string fails and return false. Otherwise continue on with the rest of the function. Never die() in a function.

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

Sidebar

Related Questions

I am querying an HTML file with LINQ-to-XML. It looks something like this: <html>
I have a very basic XML file that looks like this: <allData> <allDataDetails> <quoteid>ABC123</quoteid>
Here's what I'm trying to do. I'm querying an XML file using LINQ to
I'm having some trouble parsing malformed XML in PHP. In particular I'm querying a
I am adding a new record to XML file, first I'm querying all existing
I have an XML file which I'd like to query (read/write) in the same
This is my XML file <bookstore> <book category=COOKING> <title lang=en>Everyday Italian</title> <author>Giada De Laurentiis</author>
How do I remove/ignore the XML namespace in an xml file when querying the
So say I have this XML file: <?xml version=1.0 encoding=utf-8 standalone=yes?> <Root> <Category Name=Tasties>
I'm at a loss as to how to go about querying an XML file

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.