Serialize only part of the xml file and save it

I have a problem with XML serialization. I will try to explain this in the following example XML file

<AutoExpo>
  <Details>
    <Venue>XYZ</Venue>
    <StartTime>09:00</StartTime>
    <EndTime>21:00</EndTime>
  </Details>

  <Cars>
      <Car>
        <Company>Chevrolet</Company>
        <Model>Cruz</Model>
        <Color>Red</Color>
      </Car>

      <Car>
        <Company>Ford</Company>
        <Model>Fiesta</Model>
        <Color>Blue</Color>
      </Car>

  </Cars>
</AutoExpo>

Now that I have read this xml file, I will deserialize the cars into objects. The list of cars can be huge. My code uses these objects and can change the properties of some cars. Now, if I want to serialize only those car objects whose properties have changed, go back to the xml file and save it so that the next time my code runs, it gets the latest status information.

+3
source share
5 answers

XML , , . , , , .

XML , , , SQL Server ( ) . , .

+1

, . , . , . , / , , .

0

, XML-. , , . , , , , , , . , , , . , AutoExpo , , .

XML, , , XML . . , XML .

0

XML. . , , . , .

Jet.mdb(Access) XML . OLEDB , 32 . .

0

, .

<AutoExpo>
  <Details>
    <Venue>XYZ</Venue>
    <StartTime>09:00</StartTime>
    <EndTime>21:00</EndTime>
  </Details>

  <Cars>
    <Car id="1">
      <Company>Chevrolet</Company>
      <Model>Cruz</Model>
      <Color>Red</Color>
    </Car>
    <Car id="2">
      <Company>Ford</Company>
      <Model>Fiesta</Model>
      <Color>Blue</Color>
    </Car>
  </Cars>
</AutoExpo>

XPath , .

  • XDocument
  • : document.Element( "Car [id = 2]" )
  • : element.Element( "" ). = ""

However, the drawback of using file storage remains. You still have to load the entire file into memory and write it to your hard drive when you update the update, but you do not need to serialize all Car objects. I cannot think of an easy way to transfer a file from a hard drive and manipulate it at a time.

0
source

All Articles