0

I have a pretty complicated XML file that I need to serialize and am having trouble understanding how to do it.

I need to accept (and validate) user input to modify the fields in an XML file. I considered using LINQ to modify each but I thought Serialization/Deserialization made more sense as I need to prompt the user for MOST of the fields.

QUestion 1) Do you agree with the serialization/deserialization approach? Will this approach store the XML file in the same format it is in now?

Question 2) Is this approach possible with an XML schema this complex? Lots of different levels/types of data in one file. If so, how do I go about it?

Question 2a) Do I need to create a different class for each section? IE: one for "configSections", one for "Extedo.DBBase", etc? Or can 1 large class serialize everything?

Thanks!

XML FILE: http://www.talons-guild.com/eCTDmanager.exe.config.xml

user1797484
  • 758
  • 3
  • 10
  • 20
  • 1
    Isn't an xml file a form of serialization in itself ? – Benjamin Toueg Jan 13 '13 at 17:32
  • What do you mean? My precondition is this XML file. I have to provide a GUI to allow users to modify the values. The XML file is coming from a separate system entirely so I need to reacquire the data into my code. – user1797484 Jan 13 '13 at 17:34
  • I mean that having an xml represented as a string or a file is serialization as opposed to having it represented as an object in memory. How does this xml transit between your different system ? – Benjamin Toueg Jan 13 '13 at 17:37
  • As a file emailed from 1 team to another. I'm an outside consultant and have no say on this matter. I have to parse it ;) – user1797484 Jan 13 '13 at 17:42
  • What do you want to check : how well formatted is the xml or the content of the xml, assuming it is always well formatted ? If it the content, then you can deserialize, apply some checking rules, and reserialize it back, no matter how complex the schema is. What you risk of loosing is the comments in the original file and maybe some other minor formatting issues. – Benjamin Toueg Jan 13 '13 at 17:48
  • Understood. I think that is OKAY without the comments. I'm having trouble understanding how to do that as there are so many different levels/types of data. How do I make sure when i serialize it goes back out in the same order? Do I need a different class for each category of data that is stored in there? Also how do I serialize/deserialize parameter values? – user1797484 Jan 13 '13 at 17:51
  • if you have a xml Schema file you can give try out the code generator included with VS: http://stackoverflow.com/questions/5217665/generate-net-4-0-class-from-xsd – DasKrümelmonster Jan 13 '13 at 18:01
  • I dont, I have only that XML file :/ – user1797484 Jan 13 '13 at 18:03

1 Answers1

0

I would use XDocument to load, modify and save the config file. XPath will allow you to navigate the complexity.

Jon Canning
  • 1,602
  • 16
  • 16