|
|
|
Re: Load Data from XML url [message #183115 is a reply to message #183114] |
Wed, 09 October 2013 20:23   |
Fiver
Messages: 35 Registered: July 2013
Karma: 0
|
Member |
|
|
On 2013-10-09 21:51, Frank Catry wrote:
> Op dinsdag 8 oktober 2013 13:25:16 UTC+2 schreef Peter H. Coffin:
>> On Tue, 8 Oct 2013 01:00:07 -0700 (PDT), wrote:
>>> how can i load the data from this URL
>>> http://services.mobile.de/1.0.0/refdata/sites/GERMANY/classes/Car/makes
>>> into a array or put them into a table?
>>
>>> I wish to retrieve the values of url, key and local-description.
>>
>> http://php.net/manual/en/function.xml-parse-into-struct.php
> Hi Peter, problem is that the result of this url seems to be NOT XML
> because there are nodes / childs returned. Did you look at the XML ?
Huh? Look at the XML that is not XML?
It's XML alright. Here's something to get you started:
$doc = new DOMDocument();
$doc->load("http://services.mobile.de/ ...yadda...");
$result = [];
$items = $doc->documentElement->getElementsByTagName("item");
foreach ($items as $item) {
$result[] =[
"key" => $item->getAttribute("key"),
"url" => $item->getAttribute("url"),
"description" => $item->textContent,
];
}
print_r($result);
Assumes you can open remote files (i.e. that allow_url_fopen is enabled)
and that the XML namespaces are not important for your task.
regards,
5er
|
|
|
|
|
|
Re: Load Data from XML url [message #183309 is a reply to message #183231] |
Sun, 20 October 2013 14:08  |
Arno Welzel
Messages: 317 Registered: October 2011
Karma: 0
|
Senior Member |
|
|
Frank Catry, 2013-10-13 18:16:
> Hi 5er,
>
> indeed this line was not working.
>
> Everthings works fine execpt i have a problem with getting some special characters right in the database.
>
> 'Düvelsdor' in the XML results in 'Dücker' when loading in the DOM object and appears in this way in the database ??
Seems to be UTF-8.
> Do you know a solution ?
Use the proper encoding.
--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
|
|
|