0

I spent already a few hours trying to find a built-in function for this, but I got no results.

Does anybody have some experience on how to parse the whole data response from an XML SOAP request into a database?

What I'm looking for is a built in PHP function to do that, is there a function to do that? Or do I need to do it by my self?

nickb
  • 59,313
  • 13
  • 108
  • 143
thegrede
  • 492
  • 1
  • 6
  • 18

1 Answers1

0

Although I can't see why someone would actually want to do such a thing, you can do it by extending the SoapClient class. Now, all you have to do is get the XML string provided by the response and do whatever you want with it.

PS: If you set the 'trace' => TRUE flag, you can just call $client->__getLastRequest(), as explained here, without having to extend the SoapClient class.

Community
  • 1
  • 1
Mihai Todor
  • 8,014
  • 9
  • 49
  • 86
  • My goal is, when I got the response of SOAP I want to save the response into a database, so instead to grab all data manuelly and play around with it I want to do it with a built in function if its possible, its like when you imports a XML file into a SQL database Thank you for you answer anyways. – thegrede Jul 25 '12 at 18:31
  • So, you want to persist all the leaf nodes of an XML file to the database? Let's see... How would that work in a generic way? I mean the XML can have nodes in nodes in nodes in... Database tables are usually static. What would happen if the XML changes? Who's in charge of altering the DB structure as required? Should the DB structure adapt itself to XML structure changes? What would happen if the response XML omits certain nodes for some SOAP requests (min_occurs="0")? Should we populate the corresponding table cells with NULLs? – Mihai Todor Jul 25 '12 at 21:55
  • While you could opt for a complex EAV DB structure, I have a hard time thinking of a generic way in which you could implement a mechanism that reflects in the DB any structural changes in the XML. At best, you could handle the XML structural changes manually in the DB, if they occur, but you'll still have to deal with data type errors and all sorts of corner cases. Having said that, if the XML has a complex structure, maybe you can convert its XSD schema to DB tables automagically with some tool, but you'll still have to write some generic code which traverses the XML and persists it. – Mihai Todor Jul 25 '12 at 22:09
  • Thank you Mihai, anyways I just figured as you said and its not the way to do what I want to achieve, so I figured that the my best way is to save the XML response into a dir in my server, so I can use it when ever I want, and after 15 minutes I delete it automeaticlly, thanks anyways for your advise. – thegrede Jul 26 '12 at 01:57