从Restfull服务中合并几个xml,并将其提供给谷歌地图



我正试图从Restful服务中获取几个带有坐标的xml,并将它们合并,以便能够为商店定位器应用程序提供谷歌地图引脚。

我一直在玩弄我发现的一些想法:

$file1 = simplexml_load_file(rawurlencode('http://service.rest.com/portal-rest/countries/45/stores/12217?idLang=2' /*. urlencode('b&c')*/));
$file2 = simplexml_load_file(rawurlencode('http://service.rest.com/portal-rest/countries/74/stores/12217?idLang=2' /*. urlencode('b&c')*/));
function simplexml_merge (SimpleXMLElement &$file1, SimpleXMLElement $file2)
{
// convert SimpleXML objects into DOM ones
$dom1 = new DomDocument();
$dom2 = new DomDocument();
$dom1->loadXML($file1->asXML());
$dom2->loadXML($file2->asXML());
// pull all child elements of second XML
$xpath = new domXPath($dom2);
$xpathQuery = $xpath->query('/*/*');
for ($i = 0; $i < $xpathQuery->length; $i++)
{
// and pump them into first one
$dom1->documentElement->appendChild(
$dom1->importNode($xpathQuery->item($i), true));
}
$file1 = simplexml_import_dom($dom1);
}
$file1 = simplexml_load_string('<root><child>child 1</child></root>');
$file2 = simplexml_load_string('<root><child>child 2</child></root>');
simplexml_merge($file1, $file2);
echo($file1->asXml());
?>

但除了"child1 child2"之外,我没有得到任何输出。有人能给我指正确的方向吗?

感谢

您的示例按预期工作,输出为:

<root><child>child 1</child><child>child 2</child></root>

查看浏览器->查看源

最新更新