使用XPath搜索XML以获取“搜索结果”页面的多个值

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; }
doupu1727
doupu1727 我只想要PHP脚本搜索City,State和Zip的XML文件,然后我将显示匹配City,State,Zip,Min的所有属性。床,最小浴场,Min。出租。它通过GET从搜索表单的字段中获得。我的脚本适用于Min。BedBath,但我不知道如何添加City/State和Zip。
3 年多之前 回复
dooid3005
dooid3005 我已经添加了PHP代码,谢谢。
3 年多之前 回复
donglanche9257
donglanche9257 请显示一个完整的PHP脚本,可用于重现您的问题,并清楚地显示您希望程序输出的样子。谢谢。
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐