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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:33:43+00:00 2026-05-25T21:33:43+00:00

I have the following SimpleXML object: SimpleXMLElement Object ( [@attributes] => Array ( [status]

  • 0

I have the following SimpleXML object:

SimpleXMLElement Object
(
[@attributes] => Array
    (
        [status] => ok
    )

[a] => SimpleXMLElement Object
    (
        [b] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [c] => Google
                        [d] => GOOG
                        [e] => http://www.google.com
                    )

                [1] => SimpleXMLElement Object
                    (
                        [c] => Yahoo
                        [d] => YHOO
                        [e] => http://www.yahoo.com
                    )

                [2] => SimpleXMLElement Object
                    (
                        [c] => Microsoft
                        [d] => MSFT
                        [e] => http://www.microsoft.com
                    )

Given d I want to get e – Since b is an array, is there any way to do this without looping through the entire array?

<stk status="ok">
<a>
  <b>
    <c>Yahoo</c>
    <d>YHOO</d>
    <e>http://www.yahoo.com</e>
  </b>

  <b>
    <c>Google</c>
    <d>GOOG</d>
    <e>http://www.google.com</e>
  </b>

  <b>
    <c>Microsoft</c>
    <d>MSFT</d>
    <e>http://www.microsoft.com</e>
  </b>
</a>
</stk>
  • 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-25T21:33:44+00:00Added an answer on May 25, 2026 at 9:33 pm

    You could use an XPath query asking for the e elements that are children of b elements having d elements with the text YHOO.

    Remember that SimpleXMLElement::xpath() will return an array of elements, even if the XPath only finds one: hence $urls[0] to get the first (only) one.

    $xml  = '<stk status="ok"><a><b><c>Yahoo</c><d>YHOO</d><e>http://www.yahoo.com</e></b><b><c>Google</c><d>GOOG</d><e>http://www.google.com</e></b><b><c>Microsoft</c><d>MSFT</d><e>http://www.microsoft.com</e></b></a></stk>';
    $stk  = simplexml_load_string($xml);
    $urls = $stk->xpath('/stk/a/b[d="YHOO"]/e');
    $yhoo = (string) $urls[0];
    echo $yhoo;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple xml object file: [AuthorList] => SimpleXMLElement Object ( [@attributes]
I have a XML File in the following format: <?xml version='1.0' encoding='UTF-8'?> <entry xmlns='http://www.w3.org/2005/Atom'
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <gnm:Workbook xmlns:gnm=http://www.gnumeric.org/v10.dtd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.gnumeric.org/v9.xsd> <office:document-meta xmlns:office=urn:oasis:names:tc:opendocument:xmlns:office:1.0
I have this code: $reader = new DOMDocument(); $reader->loadHTML($shell); $xpath = new DomXPath($reader); $xpath->registerNamespace('html','http://www.w3.org/1999/xhtml');
I have a simple XML document <abc:MyForm xmlns:abc='http://myform.com'> <abc:Forms> <def:Form1 xmlns:def='http://decform.com'> .... </def:Form1> <ghi:Form2
Following suggestions on this site, I have adopted SimpleXML from org.simpleframework.xml. I use this
I have the following code which I use to load the xml object but
I have a simple xml document that looks like the following snippet. I need
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;

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.