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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:12:30+00:00 2026-05-23T11:12:30+00:00

I’m working with PHP 5.3+, specifically simplexml_load_string(). I’ve tried searching for a solution for

  • 0

I’m working with PHP 5.3+, specifically simplexml_load_string(). I’ve tried searching for a solution for a few hours with not luck, so any help would be greatly appreciated.

I need to have a systematic way of identifying all the tag names present in an XML file on a certain level.

Example XML:

<?xml version="1.0"?>
<properties>
  <property>
    <ID>243</ID>
    <area>5,000</area>
    <bathrooms>5</bathrooms>
    <bedrooms>4</bedrooms>
    <images>
      <image>http://urltoimage.com/image1.jpg</image>
      <image>http://urltoimage.com/image2.jpg</image>
    </image>
  </property>
  <property>
    <ID>332</ID>
    <garage>2</garage>
    <bathrooms>2</bathrooms>    
    <images>
      <image>http://urltoimage.com/image5.jpg</image>
      <image>http://urltoimage.com/image1.jpg</image>
    </image>    
  </property>
<properties>

I need to be able to retrieve an array of:

  • ID
  • area
  • bathrooms
  • bedrooms
  • garage

As you can see the first ‘property’ element does not have a ‘garage’, so all child elements across the XML are aggregated. I need to be able to identify all the tag names present below the ‘property’ element, ideally excluding any elements that have children. I could work around exuding elements that have children (‘images’ in this example) – but would be nice to have XPath take care of that part as well.

The reason behind this – we’re aggregating multiple XML feeds of property data that have different tag variables, and prior to importing we need to have an idea of all the different tag names used in the XML before we pass that data over to the rest of the program.

So, is there an XPath query that can be constructed? Performance is a factor and I’m not sure what the optimal configuration on PHP function is, so looking for suggestions.

  • 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-23T11:12:30+00:00Added an answer on May 23, 2026 at 11:12 am

    Try something like this

    $doc = simplexml_load_string($xml);
    $nodes = $doc->xpath('//property/*[not(*)]');
    $properties = array();
    foreach ($nodes as $node) {
        $properties[$node->getName()] = true;
    }
    $properties = array_keys($properties);
    

    Within the foreach loop, you could check to see if the value has already been entered but I figured the above would be faster.

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT

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.