Domanda

I have an XML file in which I store data about a list of persons and another one in which I store a list of objects like this.

people.xml

  <People>
     <Person>
        <Name>itsName</Name>
        <Age> itsAge </Age>
        <RecentAcquisitions>
            <Acquisition>
               <name>Apple</name>
               <quantity>5</quantity>
            </Acquisition>
        </RecentAcquisitions>
     </Person>
  </People>

objects.xml

  <Objects>
     <Object>
        <Name>Apple</Name>
        <Description>Fresh Apple</Description>
        <Price>10</Price>
        <etc>..lots of attributes..</etc>
     </Object>
  </Objects>

What is the most efficient way of extracting information from objects.xml based on the person Acquisition List at the runtime? (in example the person should have 5 objects of type "Apple").

Momentarily I use a solution which consists of storing each object from objects.xml in a list and when I'm loading a person I search for the respective object based on Acquisition->Name and add it in the person.AquisitionList;

Is there another way of doing this?

Maybe I misunderstood the XML role but it feels wrong to store the information from an XML file in a list or array at runtime.

È stato utile?

Soluzione

to my knowledge, using the runtime memory instead of constant read-write operations is the best way to do it / what you're doing is the right way.

XML can be seen as 2 things:

1 - A way to store information, much like a database, until it needs to be retrieved for processing at runtime
this is what you are doing now... you store the objects list on disk using XML, and then you retrieve it for processing/load it into memory at runtime.

2 - A standardized way of passing information around, regardless of technology.
XML can be read in a multitude of languages and any language that can read a string can technically read and extract the data from an XML document.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top