XML Requests

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sephirangel
Forum Commoner
Posts: 45
Joined: Tue Jul 15, 2008 1:37 pm

XML Requests

Post by Sephirangel »

Im currently developing a front-end client system for a reseller account using XML RPC.

The function below creates an XML request to send to the server (this is an example function):

Code: Select all

function construct_xml ($domain) { //returns XML request using user-inputted data eg: domain supplied for avaliability checking
    return <<<XML
    <?xml version='1.0' encoding='utf-8' ?>
        <rpc module='Domain' method='Availability' version='1.0'> 
            <auth> 
                <username>foo</username> 
                <password>bar</password> 
            </auth> 
            <domain datatype='domain_name'>$domain</domain>
        </rpc> 
    XML;
}
The code brings up an "unexpected $end" error on the line "<?xml version='1.0' encoding='utf-8' ?>". This is due to the "?>" of the XML declaration.
Any way to get around this using the same <<<XML return method? If not then i guess constructing and returning a string will have to do!

Thanks in advance
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: XML Requests

Post by andyhoneycutt »

use quoted strings and escape things you need as literals instead of trying to do an inline text block.
Sephirangel
Forum Commoner
Posts: 45
Joined: Tue Jul 15, 2008 1:37 pm

Re: XML Requests

Post by Sephirangel »

yeh im using it in string style now. Would of been nice to use the <<<XML method, ah well, thanks!
Post Reply