dongmengan8620 2013-03-28 05:20
浏览 10
已采纳

尝试获取wall xml相同的元素值,然后应用于其他xml

this is my general.xml file:-

<?xml version="1.0" encoding="UTF-8"?>
<results>
    <numFound>10</numFound>
    <QTime>4</QTime>
    <result>
        <distance>1071.59873299109</distance>
        <name>Irungattukottai</name>
    </result>
    <result>
            <distance>1892.33578431928</distance>
            <name>Valapuram</name>
       </result>
</results>

region.xml:-

<childrens>
    <child_5068 entity_id="5069" value="Irungattukottai" parent_id="4068"/>
    <child_5068 entity_id="7140" value="Valapuram" parent_id="4068"/>
</childrens>

product.xml:-

<products>
  <product_id value="1">
    <tab_id value="351">
      <tab_name value="test1"/>
      <dist_region value="5069"/>
      <dist_region value="5069"/>
      <dist_region value="5069"/>
    </tab_id>
  </product_id>
  <product_id value="2">
    <tab_id value="352">
      <tab_name value="test2"/>
      <dist_region value="4457"/>
      <dist_region value="7140"/>
      <dist_region value="5069"/>
    </tab_id>
  </product_id>
</products>

i have this three xml file i want to try something like this.
in general.xml file element <name>Irungattukottai</name>
if this name is exit in region.xml then get there entity_id
if entity_id is exit in product.xml then return there product_id element attribute value...

i am try this code:-

<?php
$g = file_get_contents('general.xml');
$r = file_get_contents('region.xml');
$p = file_get_contents('product.xml');

$general = simplexml_load_string($g);
$region = simplexml_load_string($r);
$product = simplexml_load_string($p);

$name = (string)$general->result->name;

if (strlen(trim($name))==0) exit('name not found');

list($entity) = $region->xpath("//*[@value='$name']/@entity_id");
$entity=(string)$entity;

if (strlen(trim($entity))==0) exit('entity_id not found');

list($prid) = $product->xpath("//dist_region[@value='$entity']/ancestor::product_id/@value");
$prid=(string)$prid;

echo "City Name:- $name, Entity_id:- $entity, Product_id:- $prid";
?>

this code is work perfact but only one value eg:-general.xml has two root in first <name>Irungattukottai</name> and in second root<name>Valapuram</name>
but my code is work only get first element not try to get wall xml file...

this is my corrent output:-

city Name:- Irungattukottai, Entity_id:- 5079, Product_id:- 1

but i want to this type of output:-

city Name:- Irungattukottai, Entity_id:- 5079, Product_id:- 1
city Name:- Valapuram , Entity_id:- 7140, Product_id:- 2
  • 写回答

4条回答 默认 最新

  • dongyingdao8867 2013-03-28 07:41
    关注

    with use of above both answer its possible try this:-

      <?php
        foreach($general->result as $row){
        if(isset($row->name)){
        //create one variable and store in value.
        $name = $row->name;
         //all you code for region.xml and then for product.xml
    
        }
        echo "name:- $name,Entity:- $entity, product:- $prid"."<br>";
        }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退