CREATE FUNCTION parseToString(IN root REFERENCE) RETURNS CHARACTER
BEGIN
DECLARE concatString character;
SET concatString = '';
CALL ComposeDetails(root,concatString);
return concatString;
END;
CREATE PROCEDURE ComposeDetails(IN root REFERENCE,INOUT concatString CHARACTER) BEGIN
DECLARE fieldName CHARACTER;
DECLARE fieldValue CHARACTER;
DECLARE cursor REFERENCE TO root;
MOVE cursor FIRSTCHILD;
WHILE LASTMOVE(cursor) Do
SET fieldName = FIELDNAME(cursor);
SET fieldValue = FIELDVALUE(cursor);
IF (fieldValue is not null) THEN
SET concatString = concatString ||'<'||fieldName||'>' ||fieldValue||'</'||fieldName||'>';
ELSE
SET concatString = concatString ||'<'||fieldName||'>';
CALL ComposeDetails(cursor, concatString );
SET concatString = concatString ||'</'||fieldName||'>';
END IF;MOVE cursor NEXTSIBLING;
END WHILE;
END;
No comments:
Post a Comment