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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:27:40+00:00 2026-06-13T13:27:40+00:00

I am learning PHP SimpleXML and I have some questions. I have been playing

  • 0

I am learning PHP SimpleXML and I have some questions.
I have been playing to get code from a web in the intranet of my work. I need generic code whenever its possible, since the code could change at any time.
In my example I select a div tag and all its children.

...
  <div class="cabTabs">
      <ul>
          <li><a href="/link1">Info1</a></li>
          <li><a href="/link2">Info2</a></li>
          <li><a href="/link3">Info3</a></li>
      </ul>
  </div>
...


//Get all web content:
$b = new sfWebBrowser(); //using symfony 1.4.17 sfWebBrower to get a SimpleXML object.
$b->get('http://intranetwebexample'); //returns a sfWebBrower object.
$xml = $b->getResponseXML(); //returns a SimpleXMLElement

//[Eclipse xdebug Watch - $xml]
"$xml"    SimpleXMLElement     
  @attributes Array [3]   
  head    SimpleXMLElement    
  body    SimpleXMLElement


//Get the div class="cabTabs".
$result = $xml->xpath('//descendant::div[@class="cabTabs"]'); 

//[Eclipse xdebug Watch - $result]
"$result" Array [1]   
  0   SimpleXMLElement    
      @attributes Array [1]   
          class   cabTabs 
      ul  SimpleXMLElement    
          li  Array [6]

Questions:

  1. The use of descendant:: prefix:
    I have read in other stackoverflow topics that descendant:: prefix is not recommended.
    In order to select a tag, and all its content, what should be the right way to do it?
    Im using the above code, but dont know if its the right way to do it.

  2. Some questions checking the Eclipse xdebug variable Watch:

2.1 Some times I cant expand the SimpleXML tree more than one or levels. In the example above, I cant access/see the below "li" node, and see its children.
Could it be a limitation of xdebug debugger with SimpleXML objects or maybe a limitation of the Eclipse Watch?
I can perfectly expand/see the "li" node when I access its parent with the usual loop: foreach($ul->li as $li).
However its not a critical bug, I think it would be perfect to see it directly and report it in the proper forum.

2.2 I dont understant at all the result code of the $xml->xpath:
If we take a look at the Eclipse Watch, the "div" tag has been converted to a 0 index key, but the "ul" and "li" tags had their original names, why?

2.3 How to access/loop xpath content with a generic code:
Im using the following Non generic code to access it:

foreach ($result as $record) {        
    foreach($record->ul as $ul) { 
        foreach($ul->li as $li) {
            foreach($li->a as $a) {
                echo ' ' . $a->name;
            }
        }
    }
}

The above code works but only if we write the right tag names. (->ul, ->li, ->a..)
What is the generic way to loop through all its content without having to specify the children name each time? (->ul, ->li, ->a..)
Also I would prefer not having to convert it to an array, unless its the right way.
I have been trying with children() property, but it doesnt work, it stops and crashes in that line: foreach ($result->children() as $ul)

Thank you a lot in advance for taking your time to read my questions. Any help is really welcome 🙂

System info:
symfony 1.4.17 with sfWebBrowserPlugin, cURL dadapter.
PHP 5.4.0 with cURL support enabled, cURL Information 7.24.0

  • 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-13T13:27:42+00:00Added an answer on June 13, 2026 at 1:27 pm
    1. I dont know I’ve never used it myself

    2. dont know i usually use Zend Debug – but i dont understand your question anyway… i think you left out some words 🙂

    2.1 PRobably xdebug/eclipse. Id check preferences theres probably a setting to limit the amount of recursion to help manage memory.

    2.2 SimpleXML::xpath Always returns an array of matched Nodes. Thats why you have integer index array as your result. So if you do //someelement you get an array of all someelement tags. You can then access their descendents in the normal fashion like $someelement->itschildelement.

    2.3 $result->children() is a good way to get at things in a generic sense. If Xdebug is crashing thats just xdebug. Either turn it off, ignore it, or find a different debugger 🙂 Xdebug is jsut a tool but shouldnt dictate how you implement things.

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

Sidebar

Related Questions

Hi I have been learning php from this book PHP Solutions Dynamic Web Design
I'm currently learning PHP and MySQL and I have been working from a basic
I have been learning PHP for some time now and I wanted one clarification.
I just started learning PHP and I have some questions about the parameters. Consider
i just got some more questions while learning PHP, does php implement any built
I have been learning php for sometime now. Besides reading books and doing tutorials
i am learning PHP, and have a piece of PHP code that queries a
I have been learning PHP/Mysql for a while. But don't yet know enough to
I just started learning PHP, and have been trying to build a website to
I Am just learning PHP and loving it so far. I have this code

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.