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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:47:09+00:00 2026-06-12T02:47:09+00:00

Say we have this XML file: <root_element> <element_1> <hello_element> Hello1 </hello_element> </element_1> <element_1> <element_2>

  • 0

Say we have this XML file:

<root_element>
    <element_1>
         <hello_element>
            Hello1
         </hello_element>
    </element_1>

    <element_1>
       <element_2>
          ...
          <element_n>
             <hello_element>
                Hello2
             </hello_element>
          </element_n>
          ...
       </element_2>
    </element_1>

</root_element>


$hello = new SimpleXMLElement('hello.xml');
echo $hello->element_1[0]->hello_element;

the output is: Hello1

echo $hello->element_1[1]->element_2-> ... ->element_n->hello_element;

the output is: Hello2

echo $hello->element_1[1]->hello_element;

the output is:

Is it possible to directly access a child element without knowing the name or number of the parent elements ?

  • 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-12T02:47:11+00:00Added an answer on June 12, 2026 at 2:47 am

    Yes, you can. Use xpath

    I think $simpleXML->xpath('/*') will get last items.

    $simpleXML->xpath('//*/*/*') that will get 3rd level items.

    (Not tested)

    SimpleXML::xpath

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

Sidebar

Related Questions

Let's say that I have something like this in my web.xml file. <filter name=foo>
let's say, I have this xml file: <?xml version=1.0 encoding=UTF-8 ?> <TimeSeries> <timeZone>1.0</timeZone> <series>
Let's say I have this XML file: <Names> <Name> <FirstName>John</FirstName> <LastName>Smith</LastName> </Name> <Name> <FirstName>James</FirstName>
Let's say I have an xml file like this: <root> <a><b><c> w </c></b></a> <x><y><z>
lets say i have an xml file path.xml that goes like this: <paths> <path
Lets say i have this XML file: <attributes> <units> <civilians> <unit> <name>Settler</name> <stats> <attack>26</attack>
So say I have this XML file: <?xml version=1.0 encoding=utf-8 standalone=yes?> <Root> <Category Name=Tasties>
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
Let's say I have this XML file. <book> <id>1</id> <title>Harry Potter - bla bla
Let's say I have an XML file such as this: <root> <level1 name=level1A> <level2

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.