{"action":"created","issue":{"url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/156","repository_url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js","labels_url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/156/labels{/name}","comments_url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/156/comments","events_url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/156/events","html_url":"https://github.com/Leonidas-from-XIV/node-xml2js/pull/156","id":41904588,"number":156,"title":"added explicitArrayProcessor","user":{"login":"ylarom","id":3155058,"avatar_url":"https://avatars.githubusercontent.com/u/3155058?v=3","gravatar_id":"","url":"https://api.github.com/users/ylarom","html_url":"https://github.com/ylarom","followers_url":"https://api.github.com/users/ylarom/followers","following_url":"https://api.github.com/users/ylarom/following{/other_user}","gists_url":"https://api.github.com/users/ylarom/gists{/gist_id}","starred_url":"https://api.github.com/users/ylarom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ylarom/subscriptions","organizations_url":"https://api.github.com/users/ylarom/orgs","repos_url":"https://api.github.com/users/ylarom/repos","events_url":"https://api.github.com/users/ylarom/events{/privacy}","received_events_url":"https://api.github.com/users/ylarom/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-09-04T07:42:09Z","updated_at":"2016-02-22T13:04:52Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/pulls/156","html_url":"https://github.com/Leonidas-from-XIV/node-xml2js/pull/156","diff_url":"https://github.com/Leonidas-from-XIV/node-xml2js/pull/156.diff","patch_url":"https://github.com/Leonidas-from-XIV/node-xml2js/pull/156.patch"},"body":"My specific case has to do with parsing iOS Xcode Storyboard XML, where tag names indicate whether the children will be single or multiple, e.g.\r\n```\r\n<scenes>\r\n  <scene>\r\n     <objects>\r\n        <view>\r\n          <subviews>\r\n             <subview>\r\n                ...\r\n```\r\nUsing hard set explicitArray to 'true' requires accessing objects awkwardly:\r\n```\r\nstoryboard.scenes[0].scene[0].objects[0].view[0]\r\n```\r\n\r\nUsing hard set explicitArray to 'false' will make the code break in different scenarios, depending on whether the parent has a single child or multiple children:\r\n```\r\nstoryboard.scenes[0].scene.objects // works when there's a single scene, breaks on multiple scenes\r\nstoryboard.scenes[0].scene[0].objects // ok when there are multiple scenes, breaks on single scenes\r\n```\r\nI added an option called explicitArrayProcessor that uses a function to determine whether a child element should be part in an array.\r\nThe function takes 2 parameters: the parent name and the child element\r\n\r\nIn my case I just check if the parent's name ends with an 's', and if so I assume child elements should be put in an array.\r\n\r\nI think this can be useful in other scenarios as well."},"comment":{"url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/comments/187161957","html_url":"https://github.com/Leonidas-from-XIV/node-xml2js/pull/156#issuecomment-187161957","issue_url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/156","id":187161957,"user":{"login":"mariomurrent-softwaresolutions","id":5072806,"avatar_url":"https://avatars.githubusercontent.com/u/5072806?v=3","gravatar_id":"","url":"https://api.github.com/users/mariomurrent-softwaresolutions","html_url":"https://github.com/mariomurrent-softwaresolutions","followers_url":"https://api.github.com/users/mariomurrent-softwaresolutions/followers","following_url":"https://api.github.com/users/mariomurrent-softwaresolutions/following{/other_user}","gists_url":"https://api.github.com/users/mariomurrent-softwaresolutions/gists{/gist_id}","starred_url":"https://api.github.com/users/mariomurrent-softwaresolutions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mariomurrent-softwaresolutions/subscriptions","organizations_url":"https://api.github.com/users/mariomurrent-softwaresolutions/orgs","repos_url":"https://api.github.com/users/mariomurrent-softwaresolutions/repos","events_url":"https://api.github.com/users/mariomurrent-softwaresolutions/events{/privacy}","received_events_url":"https://api.github.com/users/mariomurrent-softwaresolutions/received_events","type":"User","site_admin":false},"created_at":"2016-02-22T13:04:52Z","updated_at":"2016-02-22T13:04:52Z","body":"Is there a possibility to use your validator without the inflected package?"}}