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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:22:51+00:00 2026-06-13T14:22:51+00:00

Possible Duplicate: A simple program to CRUD node and node values of xml file

  • 0

Possible Duplicate:
A simple program to CRUD node and node values of xml file

How would I get a specific Attribute out of this XML feed?

Example – I have been using a line similar to this to get other XML details but I am unsure how I could change it to get a specific Attribute.

$mainPropertyDetails = $mainPropertyUrl->Attributes->attribute;

Attributes:

<Attributes>
<Attribute>
<Name>bedrooms</Name>
<DisplayName>Bedrooms</DisplayName>
<Value>4 bedrooms</Value>
</Attribute>
<Attribute>
<Name>bathrooms</Name>
<DisplayName>Bathrooms</DisplayName>
<Value>2 bathrooms</Value>
</Attribute>
<Attribute>
<Name>property_type</Name>
<DisplayName>Property type</DisplayName>
<Value>House</Value>
</Attribute>
  • 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-13T14:22:52+00:00Added an answer on June 13, 2026 at 2:22 pm

    SimpleXML implements these nodes as an array. If you were to var_dump() this, you would see something like:

    // Dump the whole Attributes array
    php > var_dump($xml->Attributes);
    
    object(SimpleXMLElement)#6 (1) {
      ["Attribute"]=>
      array(3) {
        [0]=>
        object(SimpleXMLElement)#2 (3) {
          ["Name"]=>
          string(8) "bedrooms"
          ["DisplayName"]=>
          string(8) "Bedrooms"
          ["Value"]=>
          string(10) "4 bedrooms"
        }
        [1]=>
        object(SimpleXMLElement)#5 (3) {
          ["Name"]=>
          string(9) "bathrooms"
          ["DisplayName"]=>
          string(9) "Bathrooms"
          ["Value"]=>
          string(11) "2 bathrooms"
        }
        [2]=>
        object(SimpleXMLElement)#3 (3) {
          ["Name"]=>
          string(13) "property_type"
          ["DisplayName"]=>
          string(13) "Property type"
          ["Value"]=>
          string(5) "House"
        }
      }
    }
    

    It is therefore just a matter of accessing specific ones by their array index:

    // Get the second Attribute node
    var_dump($xml->Attributes[0]->Attribute[1]);
    
    object(SimpleXMLElement)#6 (3) {
      ["Name"]=>
      string(9) "bathrooms"
      ["DisplayName"]=>
      string(9) "Bathrooms"
      ["Value"]=>
      string(11) "2 bathrooms"
    }
    

    Get the Attribute node based on a child’s value:

    Using xpath() you can query for the parent Attribute node based on a child’s text value:

    // Get the Attribute containing the Bathrooms DisplayName
    // Child's text value is queried via [AttrName/text()="value"]
    var_dump($xml->xpath('//Attributes/Attribute[DisplayName/text()="Bathrooms"]');
    
    array(1) {
      [0]=>
      object(SimpleXMLElement)#6 (3) {
        ["Name"]=>
        string(9) "bathrooms"
        ["DisplayName"]=>
        string(9) "Bathrooms"
        ["Value"]=>
        string(11) "2 bathrooms"
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: A simple program to CRUD node and node values of xml file
Possible Duplicate: A simple program to CRUD node and node values of xml file
Possible Duplicate: A simple program to CRUD node and node values of xml file
Possible Duplicate: Pygame programs hanging on exit Ran this simple program: import pygame, sys
Possible Duplicate: Storing file content into an array I'm programming a simple hangman program.
Possible Duplicate: Dirt-simple PHP templates… can this work without eval ? Let's say I
Possible Duplicate: Check if a variable is empty Simple PHP question: I have this
Possible Duplicate: Suggest a method for auto-updating my C# program I'm sorry if this
Possible Duplicate: 'ab' program freezes after lots of requests, why? Here's a simple test
Possible Duplicate: Why an executable program for a specific CPU does not work on

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.