这是我的general.xml
文件:general.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<results xmlns="http://gisgraphy.com">
<numFound>1</numFound>
<QTime>67</QTime>
<result>
<distance>1139.81967842778</distance>
<name>Rājkot</name>
<adm1Code>09</adm1Code>
<adm1Name>State of Gujarāt</adm1Name>
<asciiName>Rajkot</asciiName>
<countryCode>IN</countryCode>
<featureClass>P</featureClass>
<featureCode>PPL</featureCode>
<featureId>1258847</featureId>
<gtopo30>139</gtopo30>
<population>1177362</population>
<timezone>Asia/Kolkata</timezone>
<lat>22.299999237060547</lat>
<lng>70.78333282470703</lng>
<placeType>City</placeType>
<oneWay>false</oneWay>
<length>0.0</length>
<google_map_url>http://maps.google.com/maps?f=q&amp;ie=UTF-8&amp;iwloc=addr&amp;om=1&amp;z=12&amp;q=R%C4%81jkot&amp;ll=22.329999237060548,70.78333282470703</google_map_url>
<yahoo_map_url>http://maps.yahoo.com/broadband?mag=6&amp;mvt=m&amp;lon=70.78333282470703&amp;lat=22.299999237060547</yahoo_map_url>
<country_flag_url>/images/flags/IN.png</country_flag_url>
</result>
</results>
这是我的region.xml
文件:
<childrens>
<child_4893 entity_id="4893" value="Gujarat" parent_id="4823">
<child_4894 entity_id="4894" value="Ahmedabad" parent_id="4893"/>
<child_4895 entity_id="4895" value="Anand" parent_id="4893"/>
<child_4896 entity_id="4896" value="Bharuch (Broach)" parent_id="4893"/>
<child_4897 entity_id="4897" value="Bhavnagar" parent_id="4893"/>
<child_4898 entity_id="4898" value="Bhuj" parent_id="4893"/>
<child_4899 entity_id="4899" value="Gandhidham" parent_id="4893"/>
<child_4900 entity_id="4900" value="Gandhinagar" parent_id="4893"/>
<child_4901 entity_id="4901" value="Godhra" parent_id="4893"/>
<child_4902 entity_id="4902" value="Jamnagar" parent_id="4893"/>
<child_4903 entity_id="4903" value="Junagadh" parent_id="4893"/>
<child_4904 entity_id="4904" value="Morvi" parent_id="4893"/>
<child_4905 entity_id="4905" value="Nadiad" parent_id="4893"/>
<child_4906 entity_id="4906" value="Navsari" parent_id="4893"/>
<child_4907 entity_id="4907" value="Patan" parent_id="4893"/>
<child_4908 entity_id="4908" value="Porbandar" parent_id="4893"/>
<child_4909 entity_id="4909" value="Rajkot" parent_id="4893"/>
<child_4910 entity_id="4910" value="Surat" parent_id="4893"/>
<child_4911 entity_id="4911" value="Surendranagar" parent_id="4893"/>
<child_4912 entity_id="4912" value="Vadodara (Baroda)" parent_id="4893"/>
<child_4913 entity_id="4913" value="Vejalpur" parent_id="4893"/>
<child_4914 entity_id="4914" value="Veraval" parent_id="4893"/>
</child_4893>
</childrens>
这是我的product.xml
文件:
<products>
<product_id value="1">
<tab_id>
<tab_name value="test1" />
<dist_region value="4909"/>
<dist_region value="4909"/>
<dist_region value="4909"/>
</tab_id>
</product_id>
</products>
general.xml
文件中,有一个名为<name>
的节点元素,它是store-city
名称。region.xml
文件中是否存在此城市名称,复制相应的entity_id
。entity_id
文件中是否存在此product.xml
,如果存在则返回相应的product_id
。<name>Rajkot</name>
general.xml
Rajkot
存在于region.xml
中且相应的entity_id
为4909
entity_id
值4909
存在于product.xml
中且相应的product_id
属性值为1
product_id
值1
答案 0 :(得分:2)
使用PHP simplexml执行此操作: - &gt;看live-demo:http://codepad.viper-7.com/ax2LtQ
// $g holds general.xml, $r region.xml, $p product.xml
$general = simplexml_load_string($g);
$region = simplexml_load_string($r);
$product = simplexml_load_string($p);
$name = (string)$general->result->name;
$name = 'Rajkot' // <--- see explanation below!
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 "name: $name, entity_id: $entity, product_id: $prid";
解释:在general.xml
,<name>
= Rājkot
,region.xml
Rajkot
,没有特殊{{1} }}-字符。为了使代码有效,我必须将a
设置为$name
你需要找到一个解决方案。