php - Wrap array around SimpleXML object -


I get XML results from a web service, which I read as simple XML elements. Now there is a situation that results can vary depending on the configuration given by the web service.

The issue is: I want to wrap an array around ordinary XML objects in "position 2", so I do not later "simplify XXXXXXconfig inside the array" and "Surfag" while processing the data. Configure the form as "the difference between the object. I have been looking for a while for a while and thinking, but by now I could not find anything. Situation 1: Many simple xx elements are returned within an array

  ["myConfig"] = & gt; Array (2) {[0] = & gt; Object (simple assemment) # 41 (5) {["id"] = & gt; String (1) "1" ["type"] = & gt; String (1) "4" ["Comment"] = & gt; String (2) "Fobor" ["name"] = & gt; String (1) "Exam" ["attribute"] = & gt; String (5) "value"} [1] = & gt; Object (simple assemment) # 42 (5) {["id"] = & gt; String (1) "4" ["type"] = & gt; String (1) "2" ["Comment"] = & gt; String (8) "Twibar" ["name"] = & gt; String (10) "test2" ["attribute"] = & gt; Status 2: Configuration is simply a simple XML element, no array returned by web service  
  ["myConfig" string (5) "value"}}  
< P> position 2:] = & gt; Object (simple assemment) # 41 (5) {["id"] = & gt; String (1) "1" ["type"] = & gt; String (1) "4" ["Comment"] = & gt; String (2) "Fobor" ["name"] = & gt; String (1) "Examination" ["attribute"] = & gt; Goal 2 for the position: Before I work with configuration data, I would like to make the following on "Server 2" on server-side: string (5) "value"}

:

["myConfig"] = & gt; Array (1) {[0] = & gt; Object (simple assemment) # 41 (5) {["id"] = & gt; String (1) "1" ["type"] = & gt; String (1) "4" ["Comment"] = & gt; String (2) "Fobor" ["name"] = & gt; String (1) "Examination" ["attribute"] = & gt; String (5) "value"}}

I managed to create it and out of the array This way the SimpleXML object is working fine for this moment, but in this way I have to convert my simple XML object and issue a PHP array:

  // SimpleXML Object $ myConfig is converted to a PHP array $ fooConfig = Json_decode (json_encode (array) $ myConfig), TRUE); // Check that ['id'] ['myConfig'] has a key, if correct // and shift key = & gt; If value pairs are in the array as an array (array_key_exists ('id', $ fooConfig ['myConfig'])) {foreach ($ fooConfig ['myConfig'] $ conKey => $ conVal) { $ FooConfig ['myConfig'] [0] [$ cokey] = array_shift ($ fooConfig ['myConfig']); }}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -