Last active
January 15, 2025 18:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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