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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:18:07+00:00 2026-05-23T02:18:07+00:00

I’m receiving through cUrl an XML generated with PHP with this code: $c =

  • 0

I’m receiving through cUrl an XML generated with PHP with this code:

$c = curl_init("http://www.domain.com/script.php");
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    $xmlstr = curl_exec($c);

If I echo the $xmlstr variable it shows the following:

   <?xml version="1.0" encoding="utf-8"?>
        <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Body>
        <XGetPasoParadaREGResponse xmlns="http://tempuri.org/">
        <XGetPasoParadaREGResult>
        <PasoParada><cabecera>false</cabecera>
        <e1>
        <minutos>1</minutos>
        <metros>272</metros>
        <tipo>NORMAL</tipo>
        </e1>
        <e2>
        <minutos>7</minutos>
        <metros>1504</metros>
        <tipo>NORMAL</tipo>
        </e2><linea>28
        </linea>
        <parada>376</parada>
        <ruta>PARQUE ALCOSA</ruta>
        </PasoParada>
        </XGetPasoParadaREGResult><status>1</status></XGetPasoParadaREGResponse>
        </soap:Body>

</soap:Envelope>

Which is correct and the same generated at the script. However, if I try to do the following

$xml = simplexml_load_string($xmlstr);
    if (!is_object($xml))
        throw new Exception('Reading XML error',1001);
    echo $xml->e1->minutos;

Doesn’t show anything and print_r the object prints an empty object. What could be wrong?

  • 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-23T02:18:07+00:00Added an answer on May 23, 2026 at 2:18 am

    You have two main problems, firstly you aren’t taking into account any namespaces (e.g. soap) and secondly you aren’t traversing the XML hierarchy to get at the desired element.

    The “simple” way would be:

    $minutos = (int) $xml
                         ->children('soap', TRUE)     // <soap:*>
                         ->Body                       // <soap:Body>
                         ->children('')               //   <*> (default/no namespace prefix)
                         ->XGetPasoParadaREGResponse  //   <XGetPasoParadaREGResponse>
                         ->XGetPasoParadaREGResult    //     <XGetPasoParadaREGResult>
                         ->PasoParada                 //       <PasoParada>
                         ->e1                         //         <e1>
                         ->minutos;                   //           <minutos> yay!
    

    You could also make an XPath query for the value:

    // Our target node belongs in this namespace
    $xml->registerXPathNamespace('n', 'http://tempuri.org/');
    // Fetch <minutos> elements children to <e1>
    $nodes = $xml->xpath('//n:e1/n:minutos');
    // $nodes will always be an array, get the first item
    $minutos = (int) $nodes[0];
    

    For what it is worth, the PHP Manual contains basic usage examples covering how to traverse the XML structure and the specific pages for children() and registerXPathNamespace() show you how to work with namespaced elements with examples.

    Finally, as you have seen, the output from print_r()/var_dump() with SimpleXML is not always very helpful at all! The best way to see what you’ve got is to echo saveXML() which will display the XML for a given element.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.