Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-23-2012, 11:58 AM   PM User | #1
Tynan
Regular Coder

 
Join Date: Oct 2004
Location: London E4 UK
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Tynan is an unknown quantity at this point
xml feed into php/MYSQL listings site - noob question(s)

Hello all

i have a listings site that runs php from mysql results, all good

but now I want to take an xml feed from a client with hundreds of live listings

all new to me and i want to be sure I have the big picture right before plunging in

am I right to think that I give them an XML template which is really just a list of the fields I need and the tags for each, so more or less what I'd get from my current MYSQL query, data and markup wise?

So when my regular MYSQL query runs, I also pull the xml data from their site (or from a cache of that feed), parse it and then merge it with the array from MYSQL, on the fly server side, and then carry on as before?

Is it that simple and are there any noob dos and don'ts?

thanks
Tynan
Tynan is offline   Reply With Quote
Old 11-23-2012, 12:50 PM   PM User | #2
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
I'd advise you to use JSON -newer data format which is much easier to use.

But if you still want to use XML,
PHP has a very robust XML parser. It has many methods that will make XML parsing a breeze.


Check out phpfreaks' xml tutorial.

http://www.phpfreaks.com/tutorial/handling-xml-data
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 11-23-2012, 02:51 PM   PM User | #3
Tynan
Regular Coder

 
Join Date: Oct 2004
Location: London E4 UK
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Tynan is an unknown quantity at this point
Hi and thanks

noted but client is asking to use XML so I guess I'm stuck with what he wants to feed

Are my airey and vague assumptions correct and workable though?
Tynan is offline   Reply With Quote
Old 11-23-2012, 02:54 PM   PM User | #4
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Yeah. That's doable. Done that a lot before.

Although your job is also to advise your client. Make him see the light on JSON. Unless he has a very specific reason to use XML like that is what their feeds are made using.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 11-23-2012, 04:08 PM   PM User | #5
Tynan
Regular Coder

 
Join Date: Oct 2004
Location: London E4 UK
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Tynan is an unknown quantity at this point
Thanks, have skimmed that tutorial on the link and it looks a doddle which is nice

I'll get this one under my belt before telling people doing it already what to do I think

Thanks for your help, I may of course be back in due course
Tynan is offline   Reply With Quote
Old 03-12-2013, 01:43 PM   PM User | #6
Tynan
Regular Coder

 
Join Date: Oct 2004
Location: London E4 UK
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Tynan is an unknown quantity at this point
And here indeed I am again

I've quite happily managed to parse XML feeds and access the data and loop through it etc etc

But I'm now trying to build a php array from the xml that I can then merge with an existing array from a local MYSQL query

When my doubtless simpleton code as below runs

PHP Code:
$xml simplexml_load_file('http://www.xml2u.com/Xml/Blue%20Square_1314/2389_Default.xml');
$Properties $xml->xpath('Clients/Client/properties/Property');
//$xml = json_decode(json_encode((array) simplexml_load_file($xml)), 1);
$x=0;
foreach (
$Properties as $Property)//immoblier

{

$Ref $Property->category;

$Region $Property->Address->region;
$Department $Property->Address->subRegion;
$Town $Property->Address->location;
$ClassifiedText $Property->Description->description;
$AdTitle $Property->Description->title;
$Area $Property->Description->floorSize;
$Land $Property->PlotSize->plotSize;
$Photo1 $Property->images->image[1]->image;
$Photo2 $Property->images->image[2]->image;
$Photo3 $Property->images->image[3]->image;

$arrayBS=array(Ref=>$Ref,Region=>$Region,Department=>$Department,Town=>$Town,ClasifiedText=>$ClassifiedText,AdTitle=>$AdTitle,Area=>$Area,Land=>$Land,Photo1=>$Photo1,Photo2=>$Photo2,Photo3=>$Photo3);
$x++;
}
print_r($arrayBS); 
What on earth am I not doing right?

The xml file is as below in case it's not normal

http://www.xml2u.com/Xml/Blue%20Squa...89_Default.xml

yesterday I could create an array, today only a error

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "" in /home/rauxvsuj/public_html/ClassifiedXML.php on line 175

sorry, I'm frazzled and confused and would love someone to squint at the xml feed and point in the right direction to create a nice and easy php array, from there I can do it
Tynan is offline   Reply With Quote
Old 03-12-2013, 02:01 PM   PM User | #7
Tynan
Regular Coder

 
Join Date: Oct 2004
Location: London E4 UK
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Tynan is an unknown quantity at this point
bah, I think I'm there after posting it here, ain't that so often the way, the below copied from somewhere gives me a clean array

PHP Code:
<?php
$countries 
= array();
$dom = new DOMDocument();
$dom->load('http://www.xml2u.com/Xml/Blue%20Square_1314/2389_Default.xml');
foreach (
$dom->getElementsByTagName('properties') as $Property) {
  
$country_name $Property->getElementsByTagName('propertyid')->item(0)->textContent;
  
$country_code $Property->getElementsByTagName('category')->item(0)->textContent;
  
$countries[$country_name] = $country_name;
  
$countries[$country_code] = $country_code;
  
print_r($countries);
}
?>
Tynan is offline   Reply With Quote
Old 03-12-2013, 03:44 PM   PM User | #8
Tynan
Regular Coder

 
Join Date: Oct 2004
Location: London E4 UK
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Tynan is an unknown quantity at this point
so far so good, I can load everything into the php array except a list of images that are numbered and use the tag name 'image' nested inside another tag name of 'image', I can't get into there, I presume because the DOM code finds the outer image tag? Google not helping specifically so far

Code:
<images>
<image number="1">
<image>
http://www.emulis.net/shared/depot/3...ges/664567.jpg
</image>
<image number="2">
<image>http://www.emulis.net/shared/depot/3...ges/664565.jpg
</image>
</images>
Tynan is offline   Reply With Quote
Old 03-12-2013, 04:15 PM   PM User | #9
Tynan
Regular Coder

 
Join Date: Oct 2004
Location: London E4 UK
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Tynan is an unknown quantity at this point
Quote:
Originally Posted by Tynan View Post
so far so good, I can load everything into the php array except a list of images that are numbered and use the tag name 'image' nested inside another tag name of 'image', I can't get into there, I presume because the DOM code finds the outer image tag? Google not helping specifically so far

Code:
<images>
<image number="1">
<image>
http://www.emulis.net/shared/depot/3...ges/664567.jpg
</image>
<image number="2">
<image>http://www.emulis.net/shared/depot/3...ges/664565.jpg
</image>
</images>
hmpf, I can get the image links with the following rather obvious lines

PHP Code:
$Photo1=$Property->getElementsByTagName('image')->item(1)->textContent
but it starts going wrong when the outer image tag has a child of 'alt' as below

Code:
<images>
<image number="1">
<image>http://www.emulis.net/shared/depot/3168/biens/149506/images/627783.jpg</image><alttext/></image>
<image number="2"><image>http://www.emulis.net/shared/depot/3168/biens/149506/images/627794.jpg</image>
<alttext>Ext</alttext>
</images>
I get the alt text suffixed to the image text and I get the previous link instead of the third when I ask for


PHP Code:
$Photo3=$Property->getElementsByTagName('image')->item(3)->textContent
if you can image a third one
Tynan is offline   Reply With Quote
Old 03-12-2013, 05:34 PM   PM User | #10
Tynan
Regular Coder

 
Join Date: Oct 2004
Location: London E4 UK
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Tynan is an unknown quantity at this point
found a way around this, apologies for anyone reading my rather frenetic and unclear posts above
Tynan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:49 AM.


Advertisement
Log in to turn off these ads.