Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #11316 > unrolled thread
| Started by | frank.catry@gmail.com |
|---|---|
| First post | 2013-10-08 01:00 -0700 |
| Last post | 2013-10-20 16:08 +0200 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.php
Load Data from XML url frank.catry@gmail.com - 2013-10-08 01:00 -0700
Re: Load Data from XML url "Peter H. Coffin" <hellsop@ninehells.com> - 2013-10-08 06:25 -0500
Re: Load Data from XML url Frank Catry <frank.catry@gmail.com> - 2013-10-09 12:51 -0700
Re: Load Data from XML url Fiver <numeralfive@gmail.com> - 2013-10-09 22:23 +0200
Re: Load Data from XML url Frank Catry <frank.catry@gmail.com> - 2013-10-10 00:38 -0700
Re: Load Data from XML url Fiver <numeralfive@gmail.com> - 2013-10-12 06:17 +0200
Re: Load Data from XML url Frank Catry <frank.catry@gmail.com> - 2013-10-13 09:16 -0700
Re: Load Data from XML url Arno Welzel <usenet@arnowelzel.de> - 2013-10-20 16:08 +0200
| From | frank.catry@gmail.com |
|---|---|
| Date | 2013-10-08 01:00 -0700 |
| Subject | Load Data from XML url |
| Message-ID | <63b3437b-f172-453d-a143-390c32599e1f@googlegroups.com> |
Hi, 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. Frank.
[toc] | [next] | [standalone]
| From | "Peter H. Coffin" <hellsop@ninehells.com> |
|---|---|
| Date | 2013-10-08 06:25 -0500 |
| Message-ID | <slrnl57qss.kov.hellsop@nibelheim.ninehells.com> |
| In reply to | #11316 |
On Tue, 8 Oct 2013 01:00:07 -0700 (PDT), frank.catry@gmail.com wrote: > Hi, > 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 -- Don't eat things hawked by cartoon characters or people concealing their identities, including masks or clown makeup. It doesn't end well.
[toc] | [prev] | [next] | [standalone]
| From | Frank Catry <frank.catry@gmail.com> |
|---|---|
| Date | 2013-10-09 12:51 -0700 |
| Message-ID | <fc2b5bd2-b86d-4d6d-ad14-2f3acd4b601a@googlegroups.com> |
| In reply to | #11317 |
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: > > > Hi, > > > 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 > > > > -- > > Don't eat things hawked by cartoon characters or people concealing their > > identities, including masks or clown makeup. It doesn't end well. 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 ?
[toc] | [prev] | [next] | [standalone]
| From | Fiver <numeralfive@gmail.com> |
|---|---|
| Date | 2013-10-09 22:23 +0200 |
| Message-ID | <l34e08$6gn$1@dont-email.me> |
| In reply to | #11325 |
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
[toc] | [prev] | [next] | [standalone]
| From | Frank Catry <frank.catry@gmail.com> |
|---|---|
| Date | 2013-10-10 00:38 -0700 |
| Message-ID | <17fe35c9-f1af-42ee-bc9b-aeded8a31c6e@googlegroups.com> |
| In reply to | #11326 |
Thank you very much. Your script was not working at once so i do some changes and get it work in a few minutes.
<?php
$doc = new DOMDocument();
$doc->load("http://services.mobile.de/1.0.0/refdata/sites/GERMANY/classes/Car/makes");
$items = $doc->documentElement->getElementsByTagName("item");
foreach ($items as $item) {
$key=$item->getAttribute("key");
$description=$item->textContent;
echo "$key - $description<br>";
}
die(date('l jS \of F Y h:i:s A'));
?>
Maybe not so professional or fast as your solution but it works for me.
The values are only to load once a week into a database.
[toc] | [prev] | [next] | [standalone]
| From | Fiver <numeralfive@gmail.com> |
|---|---|
| Date | 2013-10-12 06:17 +0200 |
| Message-ID | <l3aiha$3m8$1@dont-email.me> |
| In reply to | #11341 |
On 2013-10-10 09:38, Frank Catry wrote:
> Thank you very much. Your script was not working at once so i do
> some changes and get it work in a few minutes.
>
> <?php
> $doc = new DOMDocument();
> $doc->load("http://services.mobile.de/1.0.0/refdata/sites/GERMANY/classes/Car/makes");
>
> $items = $doc->documentElement->getElementsByTagName("item");
>
> foreach ($items as $item) {
> $key=$item->getAttribute("key");
> $description=$item->textContent;
> echo "$key - $description<br>";
> }
>
> die(date('l jS \of F Y h:i:s A'));
> ?>
> Maybe not so professional or fast as your solution but it works for me.
> The values are only to load once a week into a database.
Looking good.
I'm guessing that the reason why my version didn't run for you was this:
$result = [];
..
$result[] = [ ..... ];
That's PHP 5.4 syntax. Sorry, I got used to it so quickly that I keep
forgetting about backward compatibility. In 5.3 you'd write:
$result = array();
..
$result[] = array( ..... );
Everything else should work fine in 5.3, I think.
Ah, one more thing: the "->documentElement" part can be removed, it
doesn't do anything. That was accidentally left in the example while I
was trying something else.
regards,
5er
[toc] | [prev] | [next] | [standalone]
| From | Frank Catry <frank.catry@gmail.com> |
|---|---|
| Date | 2013-10-13 09:16 -0700 |
| Message-ID | <7fb82f53-c05d-408a-9411-37db40914bbb@googlegroups.com> |
| In reply to | #11316 |
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 ?? Do you know a solution ? Frank.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2013-10-20 16:08 +0200 |
| Message-ID | <5263E3D5.8070605@arnowelzel.de> |
| In reply to | #11419 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web