I am trying to search XML using XPath code:
$results = $xml->xpath("Property/Floorplan[SquareFeet / @Min>='".$minarea."' or EffectiveRent / @Min>='".$minprice."' or Room[@RoomType='Bathroom'] / Count>='".$minbath."' or Room[@RoomType='Bedroom'] / Count>='".$minbeds."']/parent::*");
It is not working as desired. What I am looking for is, it should look into XML for Minimum Values set in Variables in SquareFeet, EffectiveRent, Room > Bedroom and Bathroom.
For example:
- $minarea= 2000,
- $minprice = 500,
- $minbath = 2,
- $minbeds = 2.
Code currently returning all nodes without matching. Also, I want to add more functionality to search for city, state and zip.
Here is my XML code:
<PhysicalProperty xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Property>
<PropertyID>
<Address AddressType="property">
<Address>518 Cedar St</Address>
<City>Monticello</City>
<State>MN</State>
<PostalCode>55362</PostalCode>
</Address>
</PropertyID>
<Floorplan>
<Room RoomType="Bedroom">
<Count>0</Count>
</Room>
<Room RoomType="Bathroom">
<Count>0</Count>
</Room>
<SquareFeet Min="1680" Max="1680"/>
<MarketRent Min="0" Max="0"/>
<EffectiveRent Min="1295" Max="1295"/>
</Floorplan>
</Property>
</PhysicalProperty>
This is the complete PHP code:
$all_active = get_template_directory().'/propertxml/propertyall.xml';
$xml=simplexml_load_file($all_active);
$results = $xml->xpath("Property/Floorplan[SquareFeet / @Min>=".$minarea." and EffectiveRent / @Min>=".$minprice." and Room[@RoomType='Bathroom'] / Count>=".$minbath." and Room[@RoomType='Bedroom'] / Count>=".$minbeds."]/parent::*");
if(!empty($results))
{
foreach($results as $res7){
$tt = $res7->PropertyID[0]->MarketingName;
$desc=$res7->Information->LongDescription;
$rent = $res7->Floorplan->EffectiveRent->attributes()->Min;
$area=$res7->Floorplan->SquareFeet->attributes()->Min ;
$bed=$res7->Floorplan->Room[0]->Count;
$bath = $res7->Floorplan->Room[1]->Count;
$url = $res7->Floorplan->FloorplanAvailabilityURL;
$address = $res7->PropertyID[0]->Address->Address;
$unitcount = $res7->Information->UnitCount;
$rent = $res7->Floorplan->EffectiveRent->attributes()->Min;
$ptype=$res7->ILS_Identification->attributes()->ILS_IdentificationType; }