refactoring to to get a document for object node and one for array node
this code uses a trait, php 5.4 have to be installed