Get a Table from XML in postgresql
There is nothing wrong with using xpath_table().

Even though some of the functions in the xml2 extension have been replaced with in-core functions, xpath_table is not one of them (I think this will happen for Postgres 10).

Until then, xpath_table() seems to be your only option:

SELECT * 
FROM xpath_table('id',
            'documents',
            'xmldata',
            '//test',
            'true') AS t(doc_id integer, data text);


Returns:

doc_id | data    
-------+---------
     1 | Red text
     1 | green   




In order for this to work you first need to create the extension (as a superuser):

create extension xml2;


Otherwise the function isn't available.