XML URL creation using Curl and PHP

I'm trying to find an elegant way to generate an XML string that is used to request data from a data provider. The site I'm building has several search boxes that take in information required for different products,

For each of these products I have a xxx_search_model that handles the programming logic for doing this. At the moment I generate the XML files in each model in string form and manually insert the variables directly into the string.

Is it possible to have the XML files in a resources folder, load them in and parse through the file inserting values? If so how would this be best done
gegaboneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HackneyCabCommented:
There may be a more XML-centric method, but I think I'd just go with the following idea:

Create your template XML documents, and then insert place-holder tokens that will be replaced by the value of variables at the time of processing. For instance,

<product>
  <id>{{productID}}</id>
  <vendor>{{vendorName}}</vendor>
</product>

and so on. Then load the file into one great big string using file_get_contents ( http://php.net/manual/en/function.file-get-contents.php ) and then use preg_replace statements to swap your place-holder tokens with the variable values.

However, you'd have to make sure that there was nothing in your XML template that resembled any of your place-holder tokens accidentally, otherwise your script may choke.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gegaboneAuthor Commented:
Perfect, thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.