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.