comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % GETXDOC retrieves an object with given id from the LTPDA
2 % repository specified by the input database connection. The object is
3 % converted from its XML text format to an Xdoc. This can then be converted
4 % into an object using the appropriate object constructor.
5 %
6 % Usage: xdoc = getXdoc(conn, id)
7 %
8 % Inputs:
9 % conn - a database connection object
10 % id - the object id
11 %
12 % Outputs:
13 % xdoc - an Xdoc representation of the object.
14 %
15 % M Hewitson 30-08-07
16 %
17 % $Id: getXdoc.m,v 1.3 2010/01/22 12:46:08 ingo Exp $
18 %
19 %
20
21 function xdoc = getXdoc(conn, id)
22
23 error('### Obsolete as of LTPDA version 2.2. Replaced my the utils class jmysql (utils.jmysql.%s)', mfilename());
24
25 try
26 curs = exec(conn, sprintf('select xml from objs where id="%d"', id));
27 curs = fetch(curs);
28 objTxt = char([curs.Data{1}].');
29 close(curs);
30 catch
31 error('### Unable to read xml for ID %d. Server returned %s', id, curs.Message);
32 end
33
34 if ~isempty(objTxt) && ~strcmp(objTxt(:), 'No Data')
35 % convert to Java string
36 str = java.lang.String(objTxt);
37 % open stream on this string
38 stream = java.io.StringBufferInputStream(str);
39 % make parser
40 builder = javax.xml.parsers.DocumentBuilderFactory.newInstance.newDocumentBuilder;
41
42 xdoc = builder.parse(stream);
43 else
44 xdoc = [];
45 end
46
47 end
48