comparison m-toolbox/classes/+utils/@jmysql/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.2 2009/06/17 11:05:53 ingo Exp $
18 %
19 %
20
21 function xdoc = getXdoc(conn, id)
22
23 xdoc = '';
24
25 try
26 results = conn.query(sprintf('select xml from objs where id="%d"', id));
27 while results.next
28 objTxt = char(results.getString(1));
29 end
30 catch curs
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