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

  • Home
  • SEARCH
  • 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 9173235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:32:32+00:00 2026-06-17T16:32:32+00:00

Possible Duplicate: Accessing @attribute from SimpleXML I am using a few third party APIs

  • 0

Possible Duplicate:
Accessing @attribute from SimpleXML

I am using a few third party APIs which returns errors via xml in the following form:

<xml>
<status>0</status>
<error code="111">Error message text goes here.</error>
</xml>

Using simplexml_load_string in PHP I can easily get the status 0 and the error message text but I cannot find a means of retrieving the code="111" value from the <error code="111">. It seems to get dropped by SimpleXML.

<?php
    $bytesRead = file_get_contents('http://api.....');
    $xml = simplexml_load_string($bytesRead);

    echo '<pre>'; print_r($xml); echo '</pre>';
?>

Outputs

SimpleXMLElement Object
(
    [status] => 0
    [error] => Error message text goes here.
)

Am I missing something? Is there a way to obtain this value or can someone suggest another method to get this?

  • 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-06-17T16:32:34+00:00Added an answer on June 17, 2026 at 4:32 pm

    It’s there but just doesn’t show in the print_r output. Like the basic examples page coins it in Example #5 Using attributes:

    So far, we have only covered the work of reading element names and their values. SimpleXML can also access element attributes. Access attributes of an element just as you would elements of an array.

    Example:

    $x = '<xml>
    <status>0</status>
    <error code="111">Error message text goes here.</error>
    </xml>';
    
    $attributeObject = simplexml_load_string($x)->error['code'];
    
    print_r($attributeObject);
    print_r((string) $attributeObject);
    

    Program Output (Demo)

    SimpleXMLElement Object
    (
        [0] => 111
    )
    111
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Accessing JSON service from localhost or file:// <script src=http://code.jquery.com/jquery-1.8.3.min.js></script> <script> $.getJSON('http://game4u.comuf.com/songs.json', function(data)
Possible Duplicate: Accessing scala.None from Java In Java you can create an instance of
Possible Duplicate: Get list of all input objects using JavaScript, without accessing a form
Possible Duplicate: accessing static member variables I have a symbol inst which is an
Possible Duplicate: accessing controls on parentform from childform I have parent form form1 and
Possible Duplicate: Accessing numerical property in a json object Using the facebook graph api,
Possible Duplicate: Accessing inherited variable from templated parent class There's this class: template<typename T>
Possible Duplicate: Accessing inherited variable from templated parent class I have been implementing a
Possible Duplicate: difference between accessing a property via “propertyname” versus “self.propertyname” in objective-c? In
Possible Duplicate: Accessing controllers from other controllers In Ember pre2 and before with the

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.