
def load_fcpxml(self): """Load and parse FCPXML file.""" try: # Register namespaces to avoid ns0, ns1 prefixes ET.register_namespace('', 'http://ns.apple.com/fcpxml/1.0') ET.register_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance') self.tree = ET.parse(self.input_file) self.root = self.tree.getroot() return True except ET.ParseError as e: print(f"Error parsing FCPXML: {e}") return False except FileNotFoundError: print(f"File not found: {self.input_file}") return False
def convert(self): """Main conversion process.""" if not self.load_fcpxml(): return False # Optionally strip namespaces if self.strip_namespace: self.strip_namespaces(self.root) # Convert to string if self.pretty: # Pretty print XML xml_str = ET.tostring(self.root, encoding='unicode', method='xml') # Add XML declaration output = '<?xml version="1.0" encoding="UTF-8"?>\n' # Simple pretty formatting from xml.dom import minidom try: dom = minidom.parseString(xml_str) output += dom.toprettyxml(indent=" ")[23:] # Skip the first line with its own declaration except: output += xml_str else: output = ET.tostring(self.root, encoding='unicode', method='xml') # Write or print output if self.output_file: with open(self.output_file, 'w', encoding='utf-8') as f: f.write(output) print(f"Converted FCPXML saved to: {self.output_file}") else: print(output) return True Fcpxml To Xml Converter
def strip_namespaces(self, element): """Remove namespace prefixes from element tags.""" # Process element tag if '}' in element.tag: element.tag = element.tag.split('}', 1)[1] # Process attributes (remove namespace from attribute names if any) new_attrs = {} for attr, value in element.attrib.items(): if '}' in attr: new_attr = attr.split('}', 1)[1] else: new_attr = attr new_attrs[new_attr] = value element.attrib.clear() element.attrib.update(new_attrs) # Recursively process children for child in element: self.strip_namespaces(child) def load_fcpxml(self): """Load and parse FCPXML file
import xml.etree.ElementTree as ET import sys import os import argparse from datetime import datetime ns1 prefixes ET.register_namespace(''
#!/usr/bin/env python3 """ FCPXML to XML Converter Converts Final Cut Pro FCPXML files to standard XML format. Handles namespaces, pretty-printing, and optional structure flattening. """