使用Python模块xml.etree.ElementTree解析有点复杂的XML并将值存储在List中

问题描述

我在XML文件下面有一个要使用ElementTree解析的文件,我想要每个变体组的特定字段,例如-

Name of Device  - Samsung Galaxy S8+ R07
Description - Libera il tuo Smartphone
SaleEffectiveDate - 2005-09-25T00:00:00
SaleExpirationDate - None
RecommendationRank - 11
Included SPS (Variants) - ['Samsung Galaxy S8+ 64 GB BLUE R07','Samsung Galaxy S8+ 64 GB Nero R07','Samsung Galaxy S8+ 64 GB Argento R07','Samsung Galaxy S8+ 64 GB Grigio R07']

<VariantGroupList noNamespaceSchemaLocation="../../Catalog.xsd">
    <Id>51b02886-ff46-48cc-8f32-cd691876f8a6</Id>
    <VariantGroup id="bb8131d5-fcd6-473b-bee2-349991d26cb3" core_data_overridden="false" logicalAreas="" action="noChange">
        <Name>
            <Value locale="en">Samsung Galaxy S8+ R07</Value>
            <Value locale="it">Samsung Galaxy S8+</Value>
        </Name>
        <VariantGroupVersions>
            <VariantGroupVersion effective="1900-01-01T00:00:00" expiration="NONE" action="noChange">
                <ID id="d9a9f43c-e3f2-4d2c-b309-3bc96bfb65e8" type="ElementaryField" value="1834887"/>
                <Description id="26bf5112-989e-41ca-a830-3759f75994de" type="ElementField">
                    <Description template_id="494db5af-237f-4554-97a4-b06acada6075">
                        <Purpose id="b71784dc-88b2-4b15-b4aa-6ccf39b45078" type="ElementaryField" value="DE"/>
                        <Description id="342c6e48-3cc3-4fa3-969e-c90e1370ede5" type="ElementaryField">
                            <Value value="Libera il tuo Smartphone" locale="en"/>
                            <Value value="Libera il tuo Smartphone" locale="it"/>
                        </Description>
                    </Description>
                </Description>
                <Code id="230b917f-44de-4813-9bd2-d3d2ca235450" type="ElementaryField" value="Galaxy_S8_Plus_R07"/>
                <SaleEffectiveDate id="4e3e446a-d605-43df-bd83-a786bbbadd6d" type="ElementaryField" value="2005-09-25T00:00:00"/>
                <SaleExpirationDate id="fea5e4f4-4186-433f-8ae1-12f979a4802e" type="ElementaryField"/>
                <Attachment id="c2f73f7f-ced7-4bde-9ab8-4c30a555b232" type="ElementField"/>
                <DisplayName id="9b257a08-1ead-4fcd-8dcb-0b4b792af6b7" type="ElementField"/>
                <Classification id="5b7f68f8-57be-4cda-9f58-45c4a1b875f5" type="ReferenceField" value="7b4ed0fa-cb80-42ae-bcdb-65b53aaf568f">
                    <Name>
                        <Value locale="en">SmartPhone Classification R07</Value>
                        <Value locale="it">SmartPhone Classification R07</Value>
                    </Name>
                    <UniqueFields>
                        <Field name="ID" type="ElementaryField" value="1143887"/>
                        <Field name="Code" type="ElementaryField" value="SmartPhone_Classification_R07"/>
                    </UniqueFields>
                </Classification>
                <RecommendationRank id="a6fc630b-8685-4a97-b1c7-755e03a424bc" type="ElementField">
                    <RecommendationRank template_id="f927faaa-bf16-470e-ad49-494e0b9bb8be">
                        <RecommendationRank id="241355fc-83b8-47aa-ba16-37abeb53bad6" type="ElementaryField" value="11"/>
                        <EffectiveDate id="84af0a80-fadb-4814-bd3b-024fe38ec1f0" type="ElementaryField" value="2005-09-25T00:00:00"/>
                        <ExpirationDate id="60819570-e7eb-4d66-b50a-d9628b3816e5" type="ElementaryField"/>
                    </RecommendationRank>
                </RecommendationRank>
                <SPSVariantRelation id="1194de7c-bf24-4793-8463-de266dd04cbe" type="ElementField">
                    <VariantGroupRelation template_id="05801ec5-aa2d-42a3-8187-7387bfc7026d">
                        <IsDefault id="18be5c15-d630-440f-9c00-2fd690ed32fe" type="ElementaryField" value="true"/>
                        <SPS id="b3a089c8-01d7-42b6-aefa-fa4fa7df923c" type="ReferenceField" value="09825c3d-97e5-42aa-9f7a-85e3ed8e6fe3">
                            <Name>
                                <Value locale="en">Samsung Galaxy S8+ 64 GB BLUE R07</Value>
                                <Value locale="it">Samsung Galaxy S8+ 64 GB BLUE</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="1767987"/>
                                <Field name="Code" type="ElementaryField" value="Galaxy_S8_plus_64GB_BLUE_R07"/>
                                <Field name="ProductOfferingID" type="ElementaryField" value="1768087"/>
                                <Field name="ProductSpecID" type="ElementaryField" value="1767887"/>
                            </UniqueFields>
                        </SPS>
                    </VariantGroupRelation>
                    <VariantGroupRelation template_id="05801ec5-aa2d-42a3-8187-7387bfc7026d">
                        <IsDefault id="18be5c15-d630-440f-9c00-2fd690ed32fe" type="ElementaryField" value="false"/>
                        <SPS id="b3a089c8-01d7-42b6-aefa-fa4fa7df923c" type="ReferenceField" value="dea07c19-df46-4aac-96a6-748116818201">
                            <Name>
                                <Value locale="en">Samsung Galaxy S8+ 64 GB Nero R07</Value>
                                <Value locale="it">Samsung Galaxy S8+ 64 GB Nero</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="1770987"/>
                                <Field name="Code" type="ElementaryField" value="Galaxy_S8_plus_64GB_BLACK_R07"/>
                                <Field name="ProductOfferingID" type="ElementaryField" value="1771087"/>
                                <Field name="ProductSpecID" type="ElementaryField" value="1770887"/>
                            </UniqueFields>
                        </SPS>
                    </VariantGroupRelation>
                    <VariantGroupRelation template_id="05801ec5-aa2d-42a3-8187-7387bfc7026d">
                        <IsDefault id="18be5c15-d630-440f-9c00-2fd690ed32fe" type="ElementaryField" value="false"/>
                        <SPS id="b3a089c8-01d7-42b6-aefa-fa4fa7df923c" type="ReferenceField" value="262175a6-80b6-4686-be57-3fc593bbec9b">
                            <Name>
                                <Value locale="en">Samsung Galaxy S8+ 64 GB Argento R07</Value>
                                <Value locale="it">Samsung Galaxy S8+ 64 GB Argento</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="1771587"/>
                                <Field name="Code" type="ElementaryField" value="Galaxy_S8_plus_64GB_SILVER_R07"/>
                                <Field name="ProductOfferingID" type="ElementaryField" value="1771687"/>
                                <Field name="ProductSpecID" type="ElementaryField" value="1771487"/>
                            </UniqueFields>
                        </SPS>
                    </VariantGroupRelation>
                    <VariantGroupRelation template_id="05801ec5-aa2d-42a3-8187-7387bfc7026d">
                        <IsDefault id="18be5c15-d630-440f-9c00-2fd690ed32fe" type="ElementaryField" value="false"/>
                        <SPS id="b3a089c8-01d7-42b6-aefa-fa4fa7df923c" type="ReferenceField" value="74002aed-d8c5-4513-8100-eb0c0e4854f2">
                            <Name>
                                <Value locale="en">Samsung Galaxy S8+ 64 GB Grigio R07</Value>
                                <Value locale="it">Samsung Galaxy S8+ 64 GB Grigio</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="1771287"/>
                                <Field name="Code" type="ElementaryField" value="Galaxy_S8_plus_64GB_GREY_R07"/>
                                <Field name="ProductOfferingID" type="ElementaryField" value="1771387"/>
                                <Field name="ProductSpecID" type="ElementaryField" value="1771187"/>
                            </UniqueFields>
                        </SPS>
                    </VariantGroupRelation>
                </SPSVariantRelation>
                <Attributes id="d7301563-e3cb-4152-a20c-1a949bdc69e4" type="ElementField">
                    <ProductAttributeRelation template_id="80a2d861-639c-4550-83b6-fc5a4de3c4b5">
                        <AssignableAttribute id="78cb950c-6fb6-40ee-b90c-6fb1662d8073" type="ReferenceField" value="80b3b095-75e9-4fec-90be-e94b9b926474">
                            <Name>
                                <Value locale="en">Capacity</Value>
                                <Value locale="it">Capacità</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="Code" type="ElementaryField" value="Internal_Memory"/>
                                <Field name="ID" type="ElementaryField" value="49180"/>
                            </UniqueFields>
                        </AssignableAttribute>
                        <Domain id="199072df-e339-498c-8902-c87595d17c56" type="ReferenceField" value="ac8434b7-d0cf-48f0-a97c-6d5f0c2e3bcb">
                            <Name>
                                <Value locale="en">AbsInternalMemory</Value>
                                <Value locale="it">AbsInternalMemory</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="AbsInternalMemory"/>
                            </UniqueFields>
                        </Domain>
                        <DefaultValue id="aabb4c36-3171-447a-ba9e-52c0f89b7fc8" type="ElementaryField" value="64GB"/>
                        <Constant id="eb6d8107-175b-4d90-86ec-d7f52aea823b" type="ElementaryField" value="false"/>
                        <UseAsServiceID id="013fc380-ff15-4640-9e74-ae4998938e4f" type="ElementaryField" value="false"/>
                        <MandatoryIndicator id="bfe6d73b-8767-49f8-a194-a01f53b158cb" type="ElementaryField" value="false"/>
                        <DisplayView id="ecc91558-f5ad-459c-92d0-08636e5a438f" type="ElementField"/>
                        <ConstantValues id="5aff9232-6c72-44d3-87d8-8938eaa0455f" type="ElementaryField">
                            <Value value="64GB"/>
                        </ConstantValues>
                        <UseAsHighlight id="033b0ca9-ad09-49f9-a22b-2c0f0f7122df" type="ElementaryField" value="true"/>
                        <UseAsVariant id="38b6e27f-21e3-4ee1-bc87-cdb3aefc7246" type="ElementaryField" value="true"/>
                        <ImpactsContract id="2fbd5a0e-a046-4bbb-9c57-01249dc81e52" type="ElementaryField" value="false"/>
                        <ProductInstanceSpecific id="ee6effe5-7270-46d3-8d04-f2b28add2bd5" type="ElementaryField" value="false"/>
                    </ProductAttributeRelation>
                    <ProductAttributeRelation template_id="80a2d861-639c-4550-83b6-fc5a4de3c4b5">
                        <AssignableAttribute id="78cb950c-6fb6-40ee-b90c-6fb1662d8073" type="ReferenceField" value="f8cba122-9d63-4fa1-9da5-380270ec7df9">
                            <Name>
                                <Value locale="en">Item Color</Value>
                                <Value locale="it">Colore</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="Code" type="ElementaryField" value="Item_Color"/>
                                <Field name="ID" type="ElementaryField" value="80380"/>
                            </UniqueFields>
                        </AssignableAttribute>
                        <Domain id="199072df-e339-498c-8902-c87595d17c56" type="ReferenceField" value="9cbc2b30-7919-41d6-9b73-2e90a3e282e5">
                            <Name>
                                <Value locale="en">AbsItemColor</Value>
                                <Value locale="it">AbsItemColor</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="AbsItemColor"/>
                            </UniqueFields>
                        </Domain>
                        <DefaultValue id="aabb4c36-3171-447a-ba9e-52c0f89b7fc8" type="ElementaryField" value="/content/dam/digitalexp/commerce/catalog/devices/colors/blue.png"/>
                        <Constant id="eb6d8107-175b-4d90-86ec-d7f52aea823b" type="ElementaryField" value="false"/>
                        <UseAsServiceID id="013fc380-ff15-4640-9e74-ae4998938e4f" type="ElementaryField" value="false"/>
                        <MandatoryIndicator id="bfe6d73b-8767-49f8-a194-a01f53b158cb" type="ElementaryField" value="false"/>
                        <DisplayView id="ecc91558-f5ad-459c-92d0-08636e5a438f" type="ElementField"/>
                        <ConstantValues id="5aff9232-6c72-44d3-87d8-8938eaa0455f" type="ElementaryField">
                            <Value value="/content/dam/digitalexp/commerce/catalog/devices/colors/blue.png"/>
                            <Value value="/content/dam/digitalexp/commerce/catalog/devices/colors/nero.png"/>
                            <Value value="/content/dam/digitalexp/commerce/catalog/devices/colors/silver.png"/>
                            <Value value="/content/dam/digitalexp/commerce/catalog/devices/colors/grey.png"/>
                        </ConstantValues>
                        <UseAsHighlight id="033b0ca9-ad09-49f9-a22b-2c0f0f7122df" type="ElementaryField" value="true"/>
                        <UseAsVariant id="38b6e27f-21e3-4ee1-bc87-cdb3aefc7246" type="ElementaryField" value="true"/>
                        <ImpactsContract id="2fbd5a0e-a046-4bbb-9c57-01249dc81e52" type="ElementaryField" value="false"/>
                        <ProductInstanceSpecific id="ee6effe5-7270-46d3-8d04-f2b28add2bd5" type="ElementaryField" value="false"/>
                    </ProductAttributeRelation>
                </Attributes>
                <ProductProperties id="d71190be-a5e2-4f01-9e44-1382f9e0afa3" type="FieldListInstanceField"/>
                <ReleaseVersion id="2661ea36-c651-4403-a8ff-5ecf9007f008" type="ElementaryField" index="1073741824" value="R0_7">
                    <Name>
                        <Value locale="en">Release 0.7</Value>
                        <Value locale="it">Release 0.7</Value>
                    </Name>
                </ReleaseVersion>
            </VariantGroupVersion>
        </VariantGroupVersions>
    </VariantGroup>
    <VariantGroup id="21914629-9ad1-40e1-8bd9-0c4fe659fa0c" core_data_overridden="false" logicalAreas="" action="noChange">
        <Name>
            <Value locale="en">Samsung Galaxy S20 FE 4G</Value>
            <Value locale="it">Samsung Galaxy S20 FE 4G</Value>
        </Name>
        <VariantGroupVersions>
            <VariantGroupVersion effective="1900-01-01T00:00:00" expiration="NONE" action="noChange">
                <ID id="d9a9f43c-e3f2-4d2c-b309-3bc96bfb65e8" type="ElementaryField" value="1753580"/>
                <Description id="26bf5112-989e-41ca-a830-3759f75994de" type="ElementField"/>
                <Code id="230b917f-44de-4813-9bd2-d3d2ca235450" type="ElementaryField" value="Samsung_Galaxy_S20_FE_4G"/>
                <SaleEffectiveDate id="4e3e446a-d605-43df-bd83-a786bbbadd6d" type="ElementaryField" value="2005-09-25T00:00:00"/>
                <SaleExpirationDate id="fea5e4f4-4186-433f-8ae1-12f979a4802e" type="ElementaryField"/>
                <Attachment id="c2f73f7f-ced7-4bde-9ab8-4c30a555b232" type="ElementField"/>
                <DisplayName id="9b257a08-1ead-4fcd-8dcb-0b4b792af6b7" type="ElementField"/>
                <Classification id="5b7f68f8-57be-4cda-9f58-45c4a1b875f5" type="ReferenceField" value="c6093dce-7cdf-45cf-ac62-7e8bc23f850f">
                    <Name>
                        <Value locale="en">Phone</Value>
                        <Value locale="it">Phone</Value>
                    </Name>
                    <UniqueFields>
                        <Field name="ID" type="ElementaryField" value="71680"/>
                        <Field name="Code" type="ElementaryField" value="Phone"/>
                    </UniqueFields>
                </Classification>
                <RecommendationRank id="a6fc630b-8685-4a97-b1c7-755e03a424bc" type="ElementField">
                    <RecommendationRank template_id="f927faaa-bf16-470e-ad49-494e0b9bb8be">
                        <RecommendationRank id="241355fc-83b8-47aa-ba16-37abeb53bad6" type="ElementaryField" value="31"/>
                        <EffectiveDate id="84af0a80-fadb-4814-bd3b-024fe38ec1f0" type="ElementaryField" value="2005-09-25T00:00:00"/>
                        <ExpirationDate id="60819570-e7eb-4d66-b50a-d9628b3816e5" type="ElementaryField"/>
                    </RecommendationRank>
                </RecommendationRank>
                <SPSVariantRelation id="1194de7c-bf24-4793-8463-de266dd04cbe" type="ElementField">
                    <VariantGroupRelation template_id="05801ec5-aa2d-42a3-8187-7387bfc7026d">
                        <IsDefault id="18be5c15-d630-440f-9c00-2fd690ed32fe" type="ElementaryField" value="false"/>
                        <SPS id="b3a089c8-01d7-42b6-aefa-fa4fa7df923c" type="ReferenceField" value="7748df6b-9f2f-4932-bc4b-6e0bb5925c21">
                            <Name>
                                <Value locale="en">Samsung Galaxy S20 FE 4G Cloud Lavender 128 GB</Value>
                                <Value locale="it">Samsung Galaxy S20 FE 4G Cloud Lavender 128 GB</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="1753080"/>
                                <Field name="Code" type="ElementaryField" value="Samsung_Galaxy_S20_FE_4G_Cloud_Lavender_128_GB"/>
                                <Field name="ProductOfferingID" type="ElementaryField" value="1753180"/>
                                <Field name="ProductSpecID" type="ElementaryField" value="1752980"/>
                            </UniqueFields>
                        </SPS>
                    </VariantGroupRelation>
                    <VariantGroupRelation template_id="05801ec5-aa2d-42a3-8187-7387bfc7026d">
                        <IsDefault id="18be5c15-d630-440f-9c00-2fd690ed32fe" type="ElementaryField" value="false"/>
                        <SPS id="b3a089c8-01d7-42b6-aefa-fa4fa7df923c" type="ReferenceField" value="6d5d7aa0-5856-444e-931a-bc158e03f0bf">
                            <Name>
                                <Value locale="en">Samsung Galaxy S20 FE 4G Cloud Mint 128 GB</Value>
                                <Value locale="it">Samsung Galaxy S20 FE 4G Cloud Mint 128 GB</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="1752480"/>
                                <Field name="Code" type="ElementaryField" value="Samsung_Galaxy_S20_FE_4G_Cloud_Mint_128_GB"/>
                                <Field name="ProductOfferingID" type="ElementaryField" value="1752580"/>
                                <Field name="ProductSpecID" type="ElementaryField" value="1752380"/>
                            </UniqueFields>
                        </SPS>
                    </VariantGroupRelation>
                    <VariantGroupRelation template_id="05801ec5-aa2d-42a3-8187-7387bfc7026d">
                        <IsDefault id="18be5c15-d630-440f-9c00-2fd690ed32fe" type="ElementaryField" value="true"/>
                        <SPS id="b3a089c8-01d7-42b6-aefa-fa4fa7df923c" type="ReferenceField" value="c9db4c64-fbae-42a4-9104-fce104c02c7a">
                            <Name>
                                <Value locale="en">Samsung Galaxy S20 FE 4G Cloud Navy 128 GB</Value>
                                <Value locale="it">Samsung Galaxy S20 FE 4G Cloud Navy 128 GB</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="1753380"/>
                                <Field name="Code" type="ElementaryField" value="Samsung_Galaxy_S20_FE_4G_Cloud_Navy_128_GB"/>
                                <Field name="ProductOfferingID" type="ElementaryField" value="1753480"/>
                                <Field name="ProductSpecID" type="ElementaryField" value="1753280"/>
                            </UniqueFields>
                        </SPS>
                    </VariantGroupRelation>
                    <VariantGroupRelation template_id="05801ec5-aa2d-42a3-8187-7387bfc7026d">
                        <IsDefault id="18be5c15-d630-440f-9c00-2fd690ed32fe" type="ElementaryField" value="false"/>
                        <SPS id="b3a089c8-01d7-42b6-aefa-fa4fa7df923c" type="ReferenceField" value="fa4d32ea-89e3-4ff5-a385-f8c4b66690e7">
                            <Name>
                                <Value locale="en">Samsung Galaxy S20 FE 4G Cloud Red 128 GB</Value>
                                <Value locale="it">Samsung Galaxy S20 FE 4G Cloud Red 128 GB</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="1752780"/>
                                <Field name="Code" type="ElementaryField" value="Samsung_Galaxy_S20_FE_4G_Cloud_Red_128_GB"/>
                                <Field name="ProductOfferingID" type="ElementaryField" value="1752880"/>
                                <Field name="ProductSpecID" type="ElementaryField" value="1752680"/>
                            </UniqueFields>
                        </SPS>
                    </VariantGroupRelation>
                </SPSVariantRelation>
                <Attributes id="d7301563-e3cb-4152-a20c-1a949bdc69e4" type="ElementField">
                    <ProductAttributeRelation template_id="80a2d861-639c-4550-83b6-fc5a4de3c4b5">
                        <AssignableAttribute id="78cb950c-6fb6-40ee-b90c-6fb1662d8073" type="ReferenceField" value="80b3b095-75e9-4fec-90be-e94b9b926474">
                            <Name>
                                <Value locale="en">Capacity</Value>
                                <Value locale="it">Capacità</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="Code" type="ElementaryField" value="Internal_Memory"/>
                                <Field name="ID" type="ElementaryField" value="49180"/>
                            </UniqueFields>
                        </AssignableAttribute>
                        <Domain id="199072df-e339-498c-8902-c87595d17c56" type="ReferenceField" value="ac8434b7-d0cf-48f0-a97c-6d5f0c2e3bcb">
                            <Name>
                                <Value locale="en">AbsInternalMemory</Value>
                                <Value locale="it">AbsInternalMemory</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="AbsInternalMemory"/>
                            </UniqueFields>
                        </Domain>
                        <DefaultValue id="aabb4c36-3171-447a-ba9e-52c0f89b7fc8" type="ElementaryField" value="128GB"/>
                        <Constant id="eb6d8107-175b-4d90-86ec-d7f52aea823b" type="ElementaryField" value="false"/>
                        <UseAsServiceID id="013fc380-ff15-4640-9e74-ae4998938e4f" type="ElementaryField" value="false"/>
                        <MandatoryIndicator id="bfe6d73b-8767-49f8-a194-a01f53b158cb" type="ElementaryField" value="false"/>
                        <DisplayView id="ecc91558-f5ad-459c-92d0-08636e5a438f" type="ElementField"/>
                        <ConstantValues id="5aff9232-6c72-44d3-87d8-8938eaa0455f" type="ElementaryField">
                            <Value value="128GB"/>
                        </ConstantValues>
                        <UseAsHighlight id="033b0ca9-ad09-49f9-a22b-2c0f0f7122df" type="ElementaryField" value="true"/>
                        <UseAsVariant id="38b6e27f-21e3-4ee1-bc87-cdb3aefc7246" type="ElementaryField" value="true"/>
                        <ImpactsContract id="2fbd5a0e-a046-4bbb-9c57-01249dc81e52" type="ElementaryField" value="false"/>
                        <ProductInstanceSpecific id="ee6effe5-7270-46d3-8d04-f2b28add2bd5" type="ElementaryField" value="false"/>
                    </ProductAttributeRelation>
                    <ProductAttributeRelation template_id="80a2d861-639c-4550-83b6-fc5a4de3c4b5">
                        <AssignableAttribute id="78cb950c-6fb6-40ee-b90c-6fb1662d8073" type="ReferenceField" value="f8cba122-9d63-4fa1-9da5-380270ec7df9">
                            <Name>
                                <Value locale="en">Item Color</Value>
                                <Value locale="it">Colore</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="Code" type="ElementaryField" value="Item_Color"/>
                                <Field name="ID" type="ElementaryField" value="80380"/>
                            </UniqueFields>
                        </AssignableAttribute>
                        <Domain id="199072df-e339-498c-8902-c87595d17c56" type="ReferenceField" value="9cbc2b30-7919-41d6-9b73-2e90a3e282e5">
                            <Name>
                                <Value locale="en">AbsItemColor</Value>
                                <Value locale="it">AbsItemColor</Value>
                            </Name>
                            <UniqueFields>
                                <Field name="ID" type="ElementaryField" value="AbsItemColor"/>
                            </UniqueFields>
                        </Domain>
                        <DefaultValue id="aabb4c36-3171-447a-ba9e-52c0f89b7fc8" type="ElementaryField" value="/content/dam/digitalexp/commerce/catalog/devices/colors/cloudnavy.png"/>
                        <Constant id="eb6d8107-175b-4d90-86ec-d7f52aea823b" type="ElementaryField" value="false"/>
                        <UseAsServiceID id="013fc380-ff15-4640-9e74-ae4998938e4f" type="ElementaryField" value="false"/>
                        <MandatoryIndicator id="bfe6d73b-8767-49f8-a194-a01f53b158cb" type="ElementaryField" value="false"/>
                        <DisplayView id="ecc91558-f5ad-459c-92d0-08636e5a438f" type="ElementField"/>
                        <ConstantValues id="5aff9232-6c72-44d3-87d8-8938eaa0455f" type="ElementaryField">
                            <Value value="/content/dam/digitalexp/commerce/catalog/devices/colors/cloudlavender.png"/>
                            <Value value="/content/dam/digitalexp/commerce/catalog/devices/colors/cloudred.png"/>
                            <Value value="/content/dam/digitalexp/commerce/catalog/devices/colors/cloudnavy.png"/>
                            <Value value="/content/dam/digitalexp/commerce/catalog/devices/colors/cloudmint.png"/>
                        </ConstantValues>
                        <UseAsHighlight id="033b0ca9-ad09-49f9-a22b-2c0f0f7122df" type="ElementaryField" value="true"/>
                        <UseAsVariant id="38b6e27f-21e3-4ee1-bc87-cdb3aefc7246" type="ElementaryField" value="true"/>
                        <ImpactsContract id="2fbd5a0e-a046-4bbb-9c57-01249dc81e52" type="ElementaryField" value="false"/>
                        <ProductInstanceSpecific id="ee6effe5-7270-46d3-8d04-f2b28add2bd5" type="ElementaryField" value="false"/>
                    </ProductAttributeRelation>
                </Attributes>
                <ProductProperties id="d71190be-a5e2-4f01-9e44-1382f9e0afa3" type="FieldListInstanceField"/>
                <ReleaseVersion id="2661ea36-c651-4403-a8ff-5ecf9007f008" type="ElementaryField" index="1073741823" value="R0_2">
                    <Name>
                        <Value locale="en">Release 0.2</Value>
                        <Value locale="it">Release 0.2</Value>
                    </Name>
                </ReleaseVersion>
            </VariantGroupVersion>
        </VariantGroupVersions>
    </VariantGroup>
</VariantGroupList>

解决方法

如果file.xml包含问题中的XML代码段,则此脚本:

from lxml import etree
root = etree.parse(r'file.xml')

for g in root.xpath('.//VariantGroup'):
    name = g.find('.//Name/Value[@locale="en"]')
    desc = g.find('.//Description/Value[@locale="en"]')
    sed = g.find('.//VariantGroupVersion/SaleEffectiveDate[@value]')
    sexd = g.find('.//VariantGroupVersion/SaleExpirationDate[@value]')
    r = g.find('.//RecommendationRank//RecommendationRank[@value]')
    variants = g.findall('.//SPS//Value[@locale="en"]')
    print('Name of Device -',name.text)
    print('Description -',desc.get('value') if desc is not None else None)
    print('SaleEffectiveDate -',sed.get('value') if sed is not None else None)
    print('SaleExpirationDate -',sexd.get('value') if sexd is not None else None)
    print('RecommendationRank -',r.get('value') if r is not None else None)
    print('Included SPS (Variants) -',[v.text for v in variants])
    print('-' * 80)

打印:

Name of Device - Samsung Galaxy S8+ R07
Description - Libera il tuo Smartphone
SaleEffectiveDate - 2005-09-25T00:00:00
SaleExpirationDate - None
RecommendationRank - 11
Included SPS (Variants) - ['Samsung Galaxy S8+ 64 GB BLUE R07','Samsung Galaxy S8+ 64 GB Nero R07','Samsung Galaxy S8+ 64 GB Argento R07','Samsung Galaxy S8+ 64 GB Grigio R07']
--------------------------------------------------------------------------------
Name of Device - Samsung Galaxy S20 FE 4G
Description - None
SaleEffectiveDate - 2005-09-25T00:00:00
SaleExpirationDate - None
RecommendationRank - 31
Included SPS (Variants) - ['Samsung Galaxy S20 FE 4G Cloud Lavender 128 GB','Samsung Galaxy S20 FE 4G Cloud Mint 128 GB','Samsung Galaxy S20 FE 4G Cloud Navy 128 GB','Samsung Galaxy S20 FE 4G Cloud Red 128 GB']
--------------------------------------------------------------------------------

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...