diff options
author | Stefan Rado <px4@sradonia.net> | 2014-02-15 21:24:53 +0100 |
---|---|---|
committer | Stefan Rado <px4@sradonia.net> | 2014-02-15 21:37:47 +0100 |
commit | d30335cb3f141fe0abf7ea853d5e5b097452a0a3 (patch) | |
tree | 1948898b70d3f909e26fafe395766b3b5fecc8ea /Tools/px4params/output_xml.py | |
parent | 1a7518a4224082cf707585a93eb6d934127e5d9e (diff) | |
download | px4-firmware-d30335cb3f141fe0abf7ea853d5e5b097452a0a3.tar.gz px4-firmware-d30335cb3f141fe0abf7ea853d5e5b097452a0a3.tar.bz2 px4-firmware-d30335cb3f141fe0abf7ea853d5e5b097452a0a3.zip |
Fixes for Python 3 and refactoring: Merge generic Output class into specialized output classes as some need to write files in binary mode.
Diffstat (limited to 'Tools/px4params/output_xml.py')
-rw-r--r-- | Tools/px4params/output_xml.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Tools/px4params/output_xml.py b/Tools/px4params/output_xml.py new file mode 100644 index 000000000..5576954c0 --- /dev/null +++ b/Tools/px4params/output_xml.py @@ -0,0 +1,25 @@ +from xml.dom.minidom import getDOMImplementation + +class XMLOutput(): + def __init__(self, groups): + impl = getDOMImplementation() + xml_document = impl.createDocument(None, "parameters", None) + xml_parameters = xml_document.documentElement + for group in groups: + xml_group = xml_document.createElement("group") + xml_group.setAttribute("name", group.GetName()) + xml_parameters.appendChild(xml_group) + for param in group.GetParams(): + xml_param = xml_document.createElement("parameter") + xml_group.appendChild(xml_param) + for code in param.GetFieldCodes(): + value = param.GetFieldValue(code) + xml_field = xml_document.createElement(code) + xml_param.appendChild(xml_field) + xml_value = xml_document.createTextNode(value) + xml_field.appendChild(xml_value) + self.output = xml_document.toprettyxml(indent=" ", newl="\n", encoding="utf-8") + + def Save(self, filename): + with open(filename, 'wb') as f: + f.write(self.output) |