TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-18-2008, 02:50 AM   #1 (permalink)
The Contributor
 
aristoworks's Avatar
 
Join Date: Nov 2007
Location: Nashville
Posts: 44
Thanks: 7
aristoworks is on a distinguished road
Default Return XML From Function

I'm working with a flash developer and using AMFPHP on the back end .

I've got a class with a function that creates a thumbnail.

I am needing to return a very simple xml string:

Quote:
<imageCacheResult>

<url>$url</url>

<thumbnail>$thumbnail</thumbnail>

</imageCacheResult>
but I'm having some difficulties.

Can anyone point me in the right direction.
Send a message via AIM to aristoworks
aristoworks is offline  
Reply With Quote
Old 01-18-2008, 03:09 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Having difficulties generating it or parsing it?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-18-2008, 08:05 PM   #3 (permalink)
The Contributor
 
aristoworks's Avatar
 
Join Date: Nov 2007
Location: Nashville
Posts: 44
Thanks: 7
aristoworks is on a distinguished road
Default

generating
Send a message via AIM to aristoworks
aristoworks is offline  
Reply With Quote
Old 01-18-2008, 08:11 PM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

in what way are you having hard time with? i.e. you dont have a clue how to start or are you getting an almighty error?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-18-2008, 08:37 PM   #5 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

i'll just assume that you dont know how to do it, PHP DOM to the rescue....again.

ach! if i have to code one more php DOM script today i think i may go completely mad ,actually thats a lie, as its already happend EHHHEHEHHHHAHAHAHAHAAH

*clears throat*

anyway back to php for a moment if we may (how ever funny insanity may be)

PHP Code:
$pDomDoc = new DomDocument('1.0');
//create root node <imageCacheResult />
$root $pDomDoc->appendChild($pDomDoc->createElement('imageCacheResult'));

//create <url /> node, then add a text node to it
$url $root->appendChild($pDomDoc->createElement('url'));
$url->appendChild($pDomDoc->createTextNode('value of url'));

//create <thumbnail />, then append a text node to it
$thumb $root->appendChild($pDomDoc->createElement('thumbnail');
$thumb->appendChild($pDomDoc->createTextNode('value of thumbnail'));

//save the xml
return $pDomDoc->saveXML(); 
that should work, hopefully and return this xml in a string:
xml Code:
<?xml version="1.0" ?>
<imageCacheResult>
    <url>value of url</url>
    <thumbnail>value of thumbnail</thumbnail>   
</imageCacheResult>
if you need to specifiy a charset, just pass it into the second param in the DomDocument construct i.e.:
PHP Code:
$pDomDoc = new DomDocument('1.0''UTF-8'); 
hope that helps
Im off to continue my insanity now gooooooooooooooobyyyyyyyyyyyeeeeee
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 01-18-2008 at 10:25 PM. Reason: fingers dont want to listen to my brain
sketchMedia is offline  
Reply With Quote
Old 01-18-2008, 10:15 PM   #6 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Going on your code sample, could you not just do something like:

PHP Code:
<?php

// ... your code here ...

$xmlResponse "<imageCacheResult>";
$xmlResponse .= "<url>$url</url>";
$xmlResponse .= "<thumbnail>$thumbnail</thumbnail>";
$xmlResponse .= "</imageCacheResult>";

return 
$xmlResponse;
?

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-18-2008, 10:19 PM   #7 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

he could, but where would the fun be i ask you???????
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-18-2008, 10:32 PM   #8 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

yea, alan's example is better suited to your needs atm, but if you needed multiple 'imageCacheResults' PHP DOM is the way to go, it will get messy pratting around with strings and loops and god knows what, although you would have to create a new root, i.e.:

xml Code:
<?xml version="1.0"?>
<imageCacheResults>
    <imageCacheResult>
        <url>value of url</url>
        <thumbnail>value of thumbnail</thumbnail>
    </imageCacheResult>
    <imageCacheResult>
         <url>value of url</url>
         <thumbnail>value of thumbnail</thumbnail>
    </imageCacheResult>
</imageCacheResults>

bah humbug im going to bed, im far to tired my brain is farting out errors again
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-18-2008, 10:37 PM   #9 (permalink)
The Contributor
 
aristoworks's Avatar
 
Join Date: Nov 2007
Location: Nashville
Posts: 44
Thanks: 7
aristoworks is on a distinguished road
Default

Hey Guys,

Sorry for not being so clear - I couldn't figure out what in the world was going on but after fooling with it I was able to pinpoint what is happening.

I've got a thumbnail creation script that fires off prior to the xml output so I'm having to set a content type header twice - and it's not working the second time. Is there any way to avoid this conflict?

Thanks
jw
Send a message via AIM to aristoworks
aristoworks is offline  
Reply With Quote
Old 01-18-2008, 11:07 PM   #10 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

Yeah, save the image to a file! You cannot output two separate content types within the same request. So, cache the thumbnail and link to that in your thumbnail parameter. Else, you'll have to turn on the override switch (header).
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:24 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design