1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * $Id: xml_data.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
19 #include <attributes.h>
29 * Compose a string for a given scalar 's'.
31 * @param mixed s - scalar to convert to a string.
32 * @return string representation of 's'.
35 compose_scalar(mixed s)
38 return "<int>" + (string) s + "</int>";
40 return "<string><![CDATA[" + s +"]]></string>";
42 return "<float>" + s +"</float>";
43 else if (objectp(s)) {
44 if ( functionp(s->get_object_id) )
45 return "<object><id>"+s->get_object_id()+"</id><name>"+
46 "<![CDATA["+s->get_identifier()+"]]></name></object>";
48 return "<function><name>"+function_name(s)+"</name>"+
49 "<object>"+function_object(s)->get_object_id()+"</object>"+
52 else if ( programp(s) )
53 return "<program>" + master()->describe_program(s) + "</program>";
58 * Bring an array into an xml representation.
60 * @param array a - the array to compose.
61 * @return xml string representation of 'a'.
64 compose_array(array a)
69 s_compose = "<array>";
70 for (i=0,sz = sizeof(a);i<sz;i++)
71 s_compose += compose(a[i]);
72 s_compose += "</array>\n";
77 * Bring a mapping into an xml representation.
79 * @param mapping m - the mapping to compose.
80 * @return xml string representation of 'm'.
84 compose_struct(mapping m)
92 s_compose = "<struct>\n";
93 for (i=0,sz=sizeof(ind);i<sz;i++)
95 s_compose += "<member>\n";
96 s_compose += "<key>" + compose(ind[i]) + "</key>\n";
97 s_compose += "<value>"+ compose(val[i]) + "</value>\n";
98 s_compose += "</member>\n";
100 s_compose +="</struct>\n";
105 * Bring any data type of pike into an xml representation.
107 * @param mixed m - some data
108 * @return xml string representation of 'm'.
113 if (stringp(m) || intp(m) || floatp(m) || objectp(m) || programp(m) )
114 return compose_scalar(m);
116 return compose_struct(m);
118 return compose_array(m);