ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Hi, heres a python function which will convert a ros message object into an xml representation. It needs to be modified if you want to use a message with arrays, but it'll work for nested structures just fine.
def ros2xml(msg, name, depth=0):
xml = "";
tabs = "\t"*depth
if hasattr(msg, "_type"):
type = msg._type
xml = xml + tabs + "<" + name + " type=\"" + type + "\">\n"
try:
for slot in msg.__slots__:
xml = xml + ros2xml(getattr(msg, slot), slot, depth=depth+1)
except:
xml = xml + tabs + str(msg)
xml = xml + tabs + "</" + name + ">\n"
else:
xml = xml + tabs + "<" + name + ">" + str(msg) + "</" + name + ">\n"
return xml