4

这是我的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;amp;ie=UTF-8&amp;amp;iwloc=addr&amp;amp;om=1&amp;amp;z=12&amp;amp;q=R%C4%81jkot&amp;amp;ll=22.329999237060548,70.78333282470703</google_map_url>
        <yahoo_map_url>http://maps.yahoo.com/broadband?mag=6&amp;amp;mvt=m&amp;amp;lon=70.78333282470703&amp;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>

解释

  1. general.xml文件中有一个名为 的节点元素<name>,它是一个store-city名称。
  2. 检查该城市名称是否存在于region.xml文件中,复制对应entity_id的 .
  3. 检查文件中是否entity_id存在,如果存在则product.xml返回相应的product_id

例如:

  • <name>Rajkot</name>取自_general.xml
  • Rajkot存在于region.xml且对应entity_id的是4909
  • entity_id4909存在于product.xml且对应的product_id属性值为1
  • 返回product_id1
4

1 回答 1

2

使用 PHP simplexml 执行此操作:--> 查看实时演示: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";

解释: in general.xml, <name>= Rājkot, in region.xmlit's Rajkot, 没有特殊a字符。为了使代码正常工作,我必须设置$nameRajkot.
您需要为此找到解决方案。

于 2013-03-23T16:40:09.847 回答