Skip to content

Instantly share code, notes, and snippets.

@jlbruno
Last active January 15, 2025 18:01
Show Gist options
  • Save jlbruno/a19ac5f2f0947d2095b193fa78f996b6 to your computer and use it in GitHub Desktop.
Save jlbruno/a19ac5f2f0947d2095b193fa78f996b6 to your computer and use it in GitHub Desktop.
Generate a list of variant product IDs from an export of a base product
import xml.etree.ElementTree as ET
# Load and parse the XML file
tree = ET.parse('C:/Users/xxxx/Downloads/product-base.xml')
root = tree.getroot()
# Define the namespace
namespace = {'ns': 'http://www.demandware.com/xml/impex/catalog/2006-10-31'}
# Find all variant elements and extract the product-id attribute
variant_ids = [variant.get('product-id') for variant in root.findall('.//ns:variant', namespace)]
# Convert the list to a comma-delimited string
variant_ids_str = ', '.join(variant_ids)
# Display the comma-delimited string
variant_ids_str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment