0

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>
  • The following may be helpful: https://stackoverflow.com/a/73640395/10024425 – Tu deschizi eu inchid Sep 16 '22 at 15:12
  • 1) Might you please [edit] your question to share a [mcve], specifically a (simplified) sample of the XML as well as "AdditionalItemProperty" content we can use to test our answers? See [ask]. 2) You have tagged this [tag:python] and [tag:c#]. In which language + framework do you want a solution? 3) Are the files large enough you have some difficulty loading them into memory, and so need some sort of streaming transformation? – dbc Sep 16 '22 at 15:52
  • If c#, [Edit a large XML file](https://stackoverflow.com/q/48574631/3744182) may be helpful. – dbc Sep 16 '22 at 20:24

0 Answers0