{"action":"created","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/7705","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/7705/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/7705/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/7705/events","html_url":"https://github.com/cakephp/cakephp/issues/7705","id":117435786,"number":7705,"title":"3.1.4 - XML::build not preserving nodes with arrays of 1 length","user":{"login":"patrickconroy","id":954577,"avatar_url":"https://avatars.githubusercontent.com/u/954577?v=3","gravatar_id":"","url":"https://api.github.com/users/patrickconroy","html_url":"https://github.com/patrickconroy","followers_url":"https://api.github.com/users/patrickconroy/followers","following_url":"https://api.github.com/users/patrickconroy/following{/other_user}","gists_url":"https://api.github.com/users/patrickconroy/gists{/gist_id}","starred_url":"https://api.github.com/users/patrickconroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrickconroy/subscriptions","organizations_url":"https://api.github.com/users/patrickconroy/orgs","repos_url":"https://api.github.com/users/patrickconroy/repos","events_url":"https://api.github.com/users/patrickconroy/events{/privacy}","received_events_url":"https://api.github.com/users/patrickconroy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cakephp/cakephp/labels/On%20hold","name":"On hold","color":"eb6420"},{"url":"https://api.github.com/repos/cakephp/cakephp/labels/utility","name":"utility","color":"ffffff"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/cakephp/cakephp/milestones/65","html_url":"https://github.com/cakephp/cakephp/milestones/3.1.5","labels_url":"https://api.github.com/repos/cakephp/cakephp/milestones/65/labels","id":1396949,"number":65,"title":"3.1.5","description":"Bugfixes and optimizations for 3.1.x","creator":{"login":"markstory","id":24086,"avatar_url":"https://avatars.githubusercontent.com/u/24086?v=3","gravatar_id":"","url":"https://api.github.com/users/markstory","html_url":"https://github.com/markstory","followers_url":"https://api.github.com/users/markstory/followers","following_url":"https://api.github.com/users/markstory/following{/other_user}","gists_url":"https://api.github.com/users/markstory/gists{/gist_id}","starred_url":"https://api.github.com/users/markstory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markstory/subscriptions","organizations_url":"https://api.github.com/users/markstory/orgs","repos_url":"https://api.github.com/users/markstory/repos","events_url":"https://api.github.com/users/markstory/events{/privacy}","received_events_url":"https://api.github.com/users/markstory/received_events","type":"User","site_admin":false},"open_issues":24,"closed_issues":41,"state":"open","created_at":"2015-11-06T03:58:46Z","updated_at":"2015-11-18T15:57:03Z","due_on":"2015-11-28T05:00:00Z","closed_at":null},"comments":8,"created_at":"2015-11-17T19:52:13Z","updated_at":"2015-11-19T01:52:24Z","closed_at":"2015-11-18T15:57:03Z","body":"Say I have this string:\r\n```\r\n<Response>\r\n    <Status>1</Status>\r\n    <Things>\r\n        <Thing>...</Thing>\r\n    </Things>\r\n</Response>\r\n```\r\n\r\nCalling `XML::build` on that will give you:\r\n```\r\nSimpleXMLElement Object\r\n(\r\n    [Status] => 1\r\n    [Things] => SimpleXMLElement Object\r\n        (\r\n            [Thing] => ...\r\n        )\r\n\r\n)\r\n```\r\n\r\nHowever, if you have multiple things, you get a different results:\r\n```\r\n<Response>\r\n    <Status>1</Status>\r\n    <Things>\r\n        <Thing>...</Thing>\r\n        <Thing>...</Thing>\r\n    </Things>\r\n</Response>\r\n```\r\n```\r\nSimpleXMLElement Object\r\n(\r\n    [Status] => 1\r\n    [Things] => SimpleXMLElement Object\r\n        (\r\n            [Thing] => Array\r\n                (\r\n                    [0] => ...\r\n                    [1] => ...\r\n                )\r\n\r\n        )\r\n)\r\n```\r\n\r\nThis means if I use a service and try to loop through the 'things' I have to first figure out if it's singular or plural in order to know where my keys start. (Or I could use an isse for the foreach but that's the same issue.)\r\n\r\n```\r\n$foo = Xml::toArray(Xml::build($s));\r\n$count = is_array($foo['Response']['Things']['Thing']) ? count($foo['Response']['Things']['Thing']) : 1;\r\nforeach ($count === 1 ? $foo['Response']['Things'] : $foo['Response']['Things']['Thing'] as $thing) {\r\n    pr($thing);\r\n}\r\n```\r\n\r\nDo you guys see that as a problem, or is that something that should be addressed?"},"comment":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/comments/157922333","html_url":"https://github.com/cakephp/cakephp/issues/7705#issuecomment-157922333","issue_url":"https://api.github.com/repos/cakephp/cakephp/issues/7705","id":157922333,"user":{"login":"markstory","id":24086,"avatar_url":"https://avatars.githubusercontent.com/u/24086?v=3","gravatar_id":"","url":"https://api.github.com/users/markstory","html_url":"https://github.com/markstory","followers_url":"https://api.github.com/users/markstory/followers","following_url":"https://api.github.com/users/markstory/following{/other_user}","gists_url":"https://api.github.com/users/markstory/gists{/gist_id}","starred_url":"https://api.github.com/users/markstory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markstory/subscriptions","organizations_url":"https://api.github.com/users/markstory/orgs","repos_url":"https://api.github.com/users/markstory/repos","events_url":"https://api.github.com/users/markstory/events{/privacy}","received_events_url":"https://api.github.com/users/markstory/received_events","type":"User","site_admin":false},"created_at":"2015-11-19T01:52:24Z","updated_at":"2015-11-19T01:52:24Z","body":"@ionas Sure, but that might be something you'd have to take up with SimpleXmlElement. Rejigging an XML document of unknown width and depth is not something I'm interested in writing or maintaining long term."}}