0

这是我的 reg.xml 文件:-

<childrens>
<child_4 entity_id="4" value="Activities" parent_id="2">
    <child_10066 entity_id="10066" value="Physical1" parent_id="4">
    <child_10067 entity_id="10067" value="Cricket" parent_id="10066">
        <child_10068 entity_id="10068" value="One Day" parent_id="10067"/>
    </child_10067>
    </child_10066>
</child_4>
<child_4331 entity_id="4331" value="Region" parent_id="2">
    <child_5069 entity_id="5069" value="Rajkot" parent_id="4331"/>
</child_4331>
</childrens>


这是我的 product.xml:-

<products>
  <product_id value="1">
    <tab_id value="351">
      <tab_name value="test1"/>
      <region_timezone value="1"/>
      <registrationstatus value="2"/>
      <eventstatus value="2"/>
      <dist_activity value="5"/>
      <dist_activity value="10068"/>
      <dist_activity value="10070"/>
      <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"/>
      <region_timezone value="1"/>
      <registrationstatus value="2"/>
      <eventstatus value="2"/>
      <dist_activity value="5"/>
      <dist_activity value="10069"/>
      <dist_activity value="10070"/>
      <dist_region value="4457"/>
      <dist_region value="7140"/>
      <dist_region value="5069"/>
   </tab_id>
  </product_id>
</products>


试过: -

<?php
 $abc= "One Day in Rajkot";
 list($first,$second) = explode(' in ',$abc);

 $text1[]=$first;
 $text2[]=$second;
 foreach($text1 as $event)
{
$event;
}
foreach($text2 as $region1)
{
$region1;
}
$r = file_get_contents('reg.xml');
$p = file_get_contents('product.xml');

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

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

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

//check the $entity in product.xml
list($prid) = $product->xpath("//*[@value='$entity']/ancestor::product_id/@value");
$prid=(string)$prid;
echo "Event:- $event, Region:- $region1, entity1:- $entity, entity2:- $entity1, Product_id:- $prid";
 ?>

我尝试在数组中传递一个字符串并拆分为差异。reg.xml如果 reg.xml 具有此值,则检查数组和此值然后到达那里entity_id此 id 匹配product.xml然后product_id从返回product.xml

我的代码工作正常,但我想将两个 xpath 合二为一

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

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

我想将这条路径设置为一个我尝试这样的事情:-

list($entity,$entity1) = $region->xpath("//*[@value='$event']and[@value='$region1']/@entity_id");
    $entity=(string)$entity;


这个你能帮我吗...

4

1 回答 1

0

您不能将两个谓词与and您所做的类似:

[@value='$event']and[@value='$region1']

但是,您可以在谓词or 内部使用:

[@value='$event' or @value='$region1']

这应该可以完成这项工作。为了您的进一步信息,您可以有多个谓词但是,它们之间没有类似的运算符and

 [@value='$event' or @value='$region1'][1]

示例:只取第一个。

于 2013-04-01T10:46:18.353 回答