Some quick notes on collxml shredding

The collxml shredding code is in shed_collxml.py and shred_collxml.sql, both in
the sql directory. Arguably, the extrnal script one should be in the scripts dir.
It will need to be altered to know about db config in that case.

The in-database method is in shred_collxml.sql It creates a function called
shed_collxml. Example usage of the in db shredder:

select shred_collxml(convert_from(file,'utf8')::text) from files natural join  module_files natural join latest_modules where moduleid = 'col10522' and filename = 'collection.xml';

example building a TOC from the trees table:

WITH RECURSIVE t(node, title, path,value, depth, corder) AS (
    SELECT nodeid, title, ARRAY[nodeid], document_id, 1, ARRAY[childorder] 
    FROM trees tr, latest_modules lm
    WHERE moduleid = 'col10522' and tr.document_id = lm.module_ident
UNION ALL
    SELECT c1.nodeid, c1.title, t.path || ARRAY[c1.nodeid], c1.document_id, t.depth+1, t.corder || ARRAY[c1.childorder] /* Recursion */
    FROM trees c1 JOIN t ON (c1.parent_id = t.node)
    WHERE not nodeid = any (t.path)
)
SELECT
    node, CASE WHEN array_upper(path,1)>1 THEN '    ' ELSE '' END ||
    REPEAT('    ', array_upper(path,1)-2) ||
    coalesce(title,name) AS "Table of Contents" FROM t left join  modules lm on t.value = lm.module_ident order by corder;

This can be wrapped in a method as well, sometime.

Ross

