Write to complex structured XML Document

Viewed 41

I am currently working on some handling of XML files and I need some inputs or ideas.

I have below showcased the structure of the files. I need to write one or more AdditionalItemProperty to the items. The catalogueLines has unique ID's, so I can find the correct items and therefore the correct place to put my AdditionalItemProperty.

The files are up to a few 100k lines, so I would rather not iterate through each files with a if statement as it would be very inefficient.

It is still possible to handle these In Memory.

So far I see two possibilities. Making queries with LINQ to find the specific item and then insert the AdditionalItemProperty at Child of Item or use a dictionary to look into while iterating through the XML file once. I am not a master of neither dictionaries or LINQ, so I would like some input or ideas before I get too deep into that. I would like for it to be possible in C# but python can be usable.

  1. Catalogue
    • CatalogueLine
      • Item
        • AdditionalItemProperty
        • AdditionalItemProperty
        • AdditionalItemProperty
    • CatalogueLine
      • Item
        • AdditionalItemProperty
        • AdditionalItemProperty
        • AdditionalItemProperty
<Catalogue>
    <cac:CatalogueLine>
        <cbc:ID>12345</cbc:ID>
        <cac:Item>
          <cbc:Name>ItemName</cbc:Name>
          <cac:AdditionalItemProperty>
            <cbc:Name>Category1</cbc:Name>
            <cbc:Value>Organic</cbc:Value>
          </cac:AdditionalItemProperty>
          <cac:AdditionalItemProperty>
            <cbc:Name>Category2</cbc:Name>
            <cbc:Value>Demeter</cbc:Value>
          </cac:AdditionalItemProperty>
        </cac:Item>
      </cac:CatalogueLine>
</Catalogue>
0 Answers
Related