Home > m > mysql > mysql_getXdoc.m

mysql_getXdoc

PURPOSE ^

MYSQL_GETXDOC retrieves an object with given id from the LTPDA

SYNOPSIS ^

function xdoc = mysql_getXdoc(conn, id)

DESCRIPTION ^

 MYSQL_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 = mysql_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: mysql_getXdoc.html,v 1.12 2008/03/31 10:27:42 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function xdoc = mysql_getXdoc(conn, id)
0002 
0003 % MYSQL_GETXDOC retrieves an object with given id from the LTPDA
0004 % repository specified by the input database connection. The object is
0005 % converted from its XML text format to an Xdoc. This can then be converted
0006 % into an object using the appropriate object constructor.
0007 %
0008 % Usage: xdoc = mysql_getXdoc(conn, id)
0009 %
0010 % Inputs:
0011 %         conn - a database connection object
0012 %         id   - the object id
0013 %
0014 % Outputs:
0015 %         xdoc - an Xdoc representation of the object.
0016 %
0017 % M Hewitson 30-08-07
0018 %
0019 % $Id: mysql_getXdoc.html,v 1.12 2008/03/31 10:27:42 hewitson Exp $
0020 %
0021 %
0022 
0023 
0024 try
0025   curs    = exec(conn, sprintf('select xml from objs where id="%d"', id));
0026   curs    = fetch(curs);
0027   objTxt  = char([curs.Data{1}].');
0028   close(curs);
0029 catch
0030   error('### Unable to read xml for ID %d. Server returned %s', id, curs.Message);
0031 end
0032 
0033 if ~isempty(objTxt) && ~strcmp(objTxt(:), 'No Data')
0034   % convert to Java string
0035   str = java.lang.String(objTxt);
0036   % open stream on this string
0037   stream = java.io.StringBufferInputStream(str);
0038   % make parser
0039   factory = javaMethod('newInstance',...
0040     'javax.xml.parsers.DocumentBuilderFactory');
0041   builder = factory.newDocumentBuilder;
0042 
0043   xdoc = builder.parse(stream);
0044 else
0045   xdoc = [];
0046 end
0047 
0048 % END

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003