Объединение вложенных элементов на основе содержимого одного элемента из нескольких URL-адресов в Python - PullRequest
0 голосов
/ 10 октября 2019

Я хочу объединить 3 XML-файла с разными URL:

XML1:

<Availability> 
 <Licence>
    <ShortIdentifier>2341</ShortIdentifier>
 </Licence>
</Availability>
  <CompList>
    <Comp>
      <CompNumber>61</CompNumber>
      <Name lang="en">comp1</Name>
      <CompType>
        <Name lang="en">comp2</Name>
      </CompType>
      <AverageInfoList>
        <AverageInfo>
          <Name lang="en">Small</Name>
        </AverageInfo>
        <AverageInfo>
          <Name lang="en">Medium</Name>
        </AverageInfo>
      </AverageInfoList>
        .
        .
        .
    </Comp>
  </CompList>

XML2:

<Availability> 
 <Licence>
    <ShortIdentifier>2341</ShortIdentifier>
 </Licence>
</Availability>
  <CompList>
    <Comp>
      <CompNumber>61</CompNumber>
      <Name lang="en">comp1</Name>
      <CompAssociationList>
        <CompAssociation>
             (a lot sub element)
        <CompAssociation>
        .
        .
        .
      </CompAssociationList>
    </Comp>
  </CompList>

XML3:

<Availability> 
 <Licence>
    <ShortIdentifier>2341</ShortIdentifier>
 </Licence>
</Availability>
  <CompList>
    <Comp>
      <CompNumber>61</ComprNumber>
      <Name lang="en">comp1</Name>
      <CompType>
        <Name lang="en">comp2</Name>
      </CompType>
      <RateList>
        <Rate>
          <RateClass>
            <Name lang="en">rate1</Name>
          </RateClass>
        </Rate>
      </RateList>
      .
      .
      .
    </Comp>
  </CompList>

Я хочу объединить их в большое дерево элементов, основанное на содержимом CompNumber, например:

<Availability> 
 <Licence>
    <ShortIdentifier>2341</ShortIdentifier>
 </Licence>
</Availability>
  <CompList>
    <Comp>
      <CompNumber>61</CompNumber>
      <Name lang="en">comp1</Name>
      <CompType>
        <Name lang="en">comp2</Name>
      </CompType>
      <AverageInfoList>
        <AverageInfo>
          <Name lang="en">Small</Name>
        </AverageInfo>
        <AverageInfo>
          <Name lang="en">Medium</Name>
        </AverageInfo>
      </AverageInfoList>
      <CompAssociationList>
        <CompAssociation>
             (a lot sub element)
        <CompAssociation>
        .
        .
        .
      </CompAssociationList>
      <RateList>
        <Rate>
          <RateClass>
            <Name lang="en">rate1</Name>
          </RateClass>
        </Rate>
      </RateList>
       .
       .
       .
    </Comp>
  </CompList>

Сейчас я начинаю объединять первые два URL-адреса и сохранять их во вложенном словаре. в пустом списке, основанном на том же CompNumber, и пересеките третьи URL. Интересно, если объединить больше URL-адресов, есть ли эффективный способ сделать это? Спасибо !!

...