diff m-toolbox/classes/+utils/@prog/obj2xml.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/@prog/obj2xml.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,35 @@
+% OBJ2XML Converts an object to an XML representation
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: Converts an object to XML representation.
+%
+% CALL:       xml = utils.prog.obj2xml(obj)
+%
+% INPUTS:     obj - the object to be converted
+%
+% OUTPUTS:    xml - the converted object
+%
+% EXAMPLE:    
+%
+% VERSION: $Id: obj2xml.m,v 1.1 2010/05/17 08:55:25 nicolodi Exp $
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function str = obj2xml(obj)
+            
+  % make pointer to xml document
+  xml = com.mathworks.xml.XMLUtils.createDocument('ltpda_object');
+
+  % extract parent node
+  parent = xml.getDocumentElement;
+  
+  % add an 'ltpda_version' attribute to the root node
+  ltpda_version = getappdata(0, 'ltpda_version');
+  parent.setAttribute('ltpda_version', ltpda_version);
+  
+  % write obj into xml
+  utils.xml.xmlwrite(obj, xml, parent, '');
+  
+  % convert into a string
+  str = xmlwrite(xml);
+end