Mercurial > hg > ltpda
diff m-toolbox/classes/+utils/@mysql/getXdoc.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@mysql/getXdoc.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,48 @@ +% GETXDOC retrieves an object with given id from the LTPDA +% repository specified by the input database connection. The object is +% converted from its XML text format to an Xdoc. This can then be converted +% into an object using the appropriate object constructor. +% +% Usage: xdoc = getXdoc(conn, id) +% +% Inputs: +% conn - a database connection object +% id - the object id +% +% Outputs: +% xdoc - an Xdoc representation of the object. +% +% M Hewitson 30-08-07 +% +% $Id: getXdoc.m,v 1.3 2010/01/22 12:46:08 ingo Exp $ +% +% + +function xdoc = getXdoc(conn, id) + + error('### Obsolete as of LTPDA version 2.2. Replaced my the utils class jmysql (utils.jmysql.%s)', mfilename()); + + try + curs = exec(conn, sprintf('select xml from objs where id="%d"', id)); + curs = fetch(curs); + objTxt = char([curs.Data{1}].'); + close(curs); + catch + error('### Unable to read xml for ID %d. Server returned %s', id, curs.Message); + end + + if ~isempty(objTxt) && ~strcmp(objTxt(:), 'No Data') + % convert to Java string + str = java.lang.String(objTxt); + % open stream on this string + stream = java.io.StringBufferInputStream(str); + % make parser + builder = javax.xml.parsers.DocumentBuilderFactory.newInstance.newDocumentBuilder; + + xdoc = builder.parse(stream); + else + xdoc = []; + end + +end +