this is my general.xml file:-
\[code\]<?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>\[/code\]region.xml:-
\[code\]<childrens> <child_5068 entity_id="5069" value="http://stackoverflow.com/questions/15674764/Irungattukottai" parent_id="4068"/> <child_5068 entity_id="7140" value="http://stackoverflow.com/questions/15674764/Valapuram" parent_id="4068"/></childrens>\[/code\]product.xml:-
\[code\]<products> <product_id value="http://stackoverflow.com/questions/15674764/1"> <tab_id value="http://stackoverflow.com/questions/15674764/351"> <tab_name value="http://stackoverflow.com/questions/15674764/test1"/> <dist_region value="http://stackoverflow.com/questions/15674764/5069"/> <dist_region value="http://stackoverflow.com/questions/15674764/5069"/> <dist_region value="http://stackoverflow.com/questions/15674764/5069"/> </tab_id> </product_id> <product_id value="http://stackoverflow.com/questions/15674764/2"> <tab_id value="http://stackoverflow.com/questions/15674764/352"> <tab_name value="http://stackoverflow.com/questions/15674764/test2"/> <dist_region value="http://stackoverflow.com/questions/15674764/4457"/> <dist_region value="http://stackoverflow.com/questions/15674764/7140"/> <dist_region value="http://stackoverflow.com/questions/15674764/5069"/> </tab_id> </product_id></products>\[/code\]i have this three xml file i want to try something like this.
in general.xml file element \[code\]<name>Irungattukottai</name>\[/code\]
if this name is exit in \[code\]region.xml\[/code\] then get there \[code\]entity_id\[/code\]
if entity_id is exit in \[code\]product.xml\[/code\] then return there \[code\]product_id\[/code\] element attribute value...i am try this code:-\[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='http://stackoverflow.com/questions/15674764/$name']/@entity_id");$entity=(string)$entity;if (strlen(trim($entity))==0) exit('entity_id not found');list($prid) = $product->xpath("//dist_region[@value='http://stackoverflow.com/questions/15674764/$entity']/ancestor:roduct_id/@value");$prid=(string)$prid;echo "City Name:- $name, Entity_id:- $entity, Product_id:- $prid";?>\[/code\]this code is work perfact but only one value eg:-\[code\]general.xml\[/code\] has two root in first \[code\]<name>Irungattukottai</name>\[/code\] and in second root\[code\]<name>Valapuram</name>\[/code\]
but my code is work only get first element not try to get wall xml file...this is my corrent output:-
\[code\]city Name:- Irungattukottai, Entity_id:- 5079, Product_id:- 1\[/code\]but i want to this type of output:-
\[code\]city Name:- Irungattukottai, Entity_id:- 5079, Product_id:- 1city Name:- Valapuram , Entity_id:- 7140, Product_id:- 2\[/code\]
\[code\]<?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>\[/code\]region.xml:-
\[code\]<childrens> <child_5068 entity_id="5069" value="http://stackoverflow.com/questions/15674764/Irungattukottai" parent_id="4068"/> <child_5068 entity_id="7140" value="http://stackoverflow.com/questions/15674764/Valapuram" parent_id="4068"/></childrens>\[/code\]product.xml:-
\[code\]<products> <product_id value="http://stackoverflow.com/questions/15674764/1"> <tab_id value="http://stackoverflow.com/questions/15674764/351"> <tab_name value="http://stackoverflow.com/questions/15674764/test1"/> <dist_region value="http://stackoverflow.com/questions/15674764/5069"/> <dist_region value="http://stackoverflow.com/questions/15674764/5069"/> <dist_region value="http://stackoverflow.com/questions/15674764/5069"/> </tab_id> </product_id> <product_id value="http://stackoverflow.com/questions/15674764/2"> <tab_id value="http://stackoverflow.com/questions/15674764/352"> <tab_name value="http://stackoverflow.com/questions/15674764/test2"/> <dist_region value="http://stackoverflow.com/questions/15674764/4457"/> <dist_region value="http://stackoverflow.com/questions/15674764/7140"/> <dist_region value="http://stackoverflow.com/questions/15674764/5069"/> </tab_id> </product_id></products>\[/code\]i have this three xml file i want to try something like this.
in general.xml file element \[code\]<name>Irungattukottai</name>\[/code\]
if this name is exit in \[code\]region.xml\[/code\] then get there \[code\]entity_id\[/code\]
if entity_id is exit in \[code\]product.xml\[/code\] then return there \[code\]product_id\[/code\] element attribute value...i am try this code:-\[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='http://stackoverflow.com/questions/15674764/$name']/@entity_id");$entity=(string)$entity;if (strlen(trim($entity))==0) exit('entity_id not found');list($prid) = $product->xpath("//dist_region[@value='http://stackoverflow.com/questions/15674764/$entity']/ancestor:roduct_id/@value");$prid=(string)$prid;echo "City Name:- $name, Entity_id:- $entity, Product_id:- $prid";?>\[/code\]this code is work perfact but only one value eg:-\[code\]general.xml\[/code\] has two root in first \[code\]<name>Irungattukottai</name>\[/code\] and in second root\[code\]<name>Valapuram</name>\[/code\]
but my code is work only get first element not try to get wall xml file...this is my corrent output:-
\[code\]city Name:- Irungattukottai, Entity_id:- 5079, Product_id:- 1\[/code\]but i want to this type of output:-
\[code\]city Name:- Irungattukottai, Entity_id:- 5079, Product_id:- 1city Name:- Valapuram , Entity_id:- 7140, Product_id:- 2\[/code\]