我收到一个结构如下的旅游 XML 文档:
<msResult timestamp="20130507153907">
<places>
<place id="1000008" name="Germany" placePath="1000008"/>
<place id="1000591" name="Berlin" placePath="10000081000591"/>
</places>
<rooms>
<room id="1002" name="Standard"/>
<room id="1042" name="Standart"/>
</rooms>
<foods>
<food id="2" name="BB" description="Breakfast"/>
<food id="1" name="No" description="No food"/>
</foods>
<hotels>
<hotel categoryId="6"/>
<hotel id="9047" placeId="1000591" name="BERLIN EXCELSIOR" categoryId="8" desc="en"/>
<hotel id="37803" placeId="1000591" name="MARK APART" categoryId="6" desc="en"/>
</hotels>
<routes>
<route id="223534">
<point>
<place placeId="1000591" hotelId="37803" categoryId="6" foodId="1" tourTypeIds="1" roomId="1002"/>
</point>
</route>
<route id="223535">
<point>
<place placeId="1000591" hotelId="9047" categoryId="8" foodId="1" tourTypeIds="1" roomId="1042"/>
</point>
</route>
</routes>
<tours>
<group departureId="64" currencyId="2" transportIds="1" includeIds="1 2 32" include="description" exclude="" comment="" program="" transport="">
<tourGroup duration="3" routeId="223534" statusId="3" tourTypeIds="1" dates="17.05.2013">
<tour accomId="6" price="850" ids="1339755026"/>
</tourGroup>
</group>
<group departureId="64" currencyId="2" transportIds="1" includeIds="1 2 32" include="descriptiin" exclude="" comment="" program="" transport="">
<tourGroup duration="3" routeId="223534" statusId="3" tourTypeIds="1" dates="31.05.2013">
<tour accomId="6" price="902" ids="1339755024"/>
</tourGroup>
</group>
<group departureId="64" currencyId="2" transportIds="1" includeIds="1 2 32" include="description" exclude="" comment="" program="" transport="">
<tourGroup duration="3" routeId="223535" statusId="3" tourTypeIds="1" dates="17.05.2013">
<tour accomId="6" price="981" ids="1339755027"/>
</tourGroup>
</group>
</tours>
</msResult>
我需要像这样输出每个游览:
城市名称 | 酒店名称 | 房型 | 食物种类 | 开始日期 | 持续时间 | 价格
我当前的 PHP 代码是这样的:
$xml = simplexml_load_string($out);
foreach ($xml->places->place as $place) {
?>
<h5><?php echo $place["name"]; ?> -
<?php
}
foreach ($xml->tours->group as $group) {
?>
Date: <?php echo $group->tourGroup["dates"]; ?> -
Days: <?php echo $group->tourGroup["duration"]; ?> -
Price: $<?php echo $group->tourGroup->tour["price"];
}
这可行,但不幸的是它只输出单独的 XML 值。
为了正确获得整个结构,我需要将非常量值与相同的值"routeId=xxx"
相关联,然后我可以从中获取in并输出from ,然后对 and 执行相同的操作并输出from等。我希望这有点道理。<tourGroup>
<route id="xxx">
"id"
<place placeId="xxx">
"name"
<places>
<place id="xxx" name="...">
<hotelId="xxx">
"name"
<hotels>
<hotel id="xxx" name="...">
<roomId>
<foodId>
不幸的是,我无法理解这一点,而且我的 PHP 知识非常基础,但如果有人能指出我正确的方向,我将不胜感激。谢谢!