dpjo15650 2017-02-02 19:12
浏览 45

使用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; }
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛