We help IT Professionals succeed at work.
Get Started

php parse xml post to database

Richard Winnick
Last Modified: 2012-05-10
Hi -
I am a beginner with xml and moderately comfortable with PHP -
I have been trying to make this work for longer than you would believe -
and am totally confused after all the articles and posts I have read about xml -
and I am obviously still missing something -

A third party provider is posting the following xml string to me -

<?xml version=\1.0\" encoding=\"utf-8\" ?><IvrData><TemplateID>21</TemplateID><QueueID>634257052820310008</QueueID><Attempt>2</Attempt><CallTime>2010-11-18T19:42:11-05:00</CallTime><Telephone>2072655421</Telephone><CallResult>PVD</CallResult><ReferenceID>8</ReferenceID><Items><Item id=\"1\" value=\"1\" variable=\"JXC9B9MQDK-2-8-1\" /><Item id=\"2\" value=\"2\" variable=\"BXK7MZDNZQ-2-8-2\" /></Items></IvrData>

The xml string can have several item id tags with their value and variable name attributes -
I need to parse the xml and put the Item id's with their values and variable names into my MYSQL database -

I have been able to 'grab' the entire xml string using $Data = $_POST["Data"]
But I have been unable to parse the contents of the $Data variable -

I have tried using simplexml_load_string($Data)
But there doesn't seem to be anything there -

Thanks in advance for any help -
and please remember I'm just starting with xml :-)
Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 1 Answer and 19 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE