Writes this element as a single standalone XML file @type path: string @param path: The path to the file to write @type with_xml_declaration: boolean @param with_xml_declaration: True to include the XML declaration at the top of the file (the default), or False to exc
(self, path, with_xml_declaration=True)
| 909 | return None |
| 910 | |
| 911 | def writeToFile(self, path, with_xml_declaration=True): |
| 912 | """Writes this element as a single standalone XML file |
| 913 | @type path: string |
| 914 | @param path: The path to the file to write |
| 915 | @type with_xml_declaration: boolean |
| 916 | @param with_xml_declaration: True to include the XML declaration at the top of the file (the default), or False to exclude it |
| 917 | |
| 918 | @rtype: boolean |
| 919 | @return: True on success, otherwise False |
| 920 | """ |
| 921 | if not self or self is None: |
| 922 | return False |
| 923 | if not self.element or self.element is None: |
| 924 | return False |
| 925 | if not path or path is None: |
| 926 | return False |
| 927 | |
| 928 | try: |
| 929 | namespace = self.getNamespace() |
| 930 | # Register this namespace with the parser as the default namespace |
| 931 | xml.etree.ElementTree.register_namespace("", namespace) |
| 932 | xml.etree.ElementTree.register_namespace( |
| 933 | "def", "http://oval.mitre.org/XMLSchema/oval-definitions-5" |
| 934 | ) |
| 935 | xml.etree.ElementTree.register_namespace( |
| 936 | "oval", "http://oval.mitre.org/XMLSchema/oval-common-5" |
| 937 | ) |
| 938 | xml.etree.ElementTree.register_namespace( |
| 939 | "xsi", "http://www.w3.org/2001/XMLSchema-instance" |
| 940 | ) |
| 941 | |
| 942 | e = self.getElement() |
| 943 | # Fix up the element so it will print nicely |
| 944 | OvalDocument.indent(e) |
| 945 | # Create a new ElementTree with this element as the root |
| 946 | tree = ElementTree(e) |
| 947 | # And finally, write the full tree to a file |
| 948 | tree.write(path, "UTF-8", with_xml_declaration) |
| 949 | |
| 950 | return True |
| 951 | |
| 952 | except Exception: |
| 953 | return False |
| 954 | |
| 955 | @staticmethod |
| 956 | def fromStandaloneFile(path): |
nothing calls this directly
no test coverage detected