I have an XML file which contains 1) a serialized object and 2) a serialized hashtable. Here is my pseudo xml file(data.xml):
//PROPERTIES of an object called "Information"
<?xml version="1.0" encoding="utf-8"?>
<Information xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CompileScript>false</CompileScript>
<SaveScript>false</SaveScript>
<ConvertPaths>false</ConvertPaths>
<UseUninstaller>true</UseUninstaller>
<UninstallSuccess>[NAME] was successfully removed from your computer. </UninstallSuccess>
<UninstallPrompt>Are you sure you want to completely remove [NAME] and all of its components?</UninstallPrompt>
<AllowChangeStartMenuFolderName>false</AllowChangeStartMenuFolderName>
//... (many others)
//Here starts KEYS & VALUES of my hashtable
<entry>
<fileName> My file name 1</fileName>
<instDir>My file location 1</instDir>
</entry>
<entry>
<fileName> My file name 2</fileName>
<instDir>My file location 2</instDir>
</entry>
//...and so on.
My goal is to deserialize half of the XML file (up to "AllowChangeStartMenuFolderName") back to "Information" object and the remaining part back to a hashtable. My concerns:
- How do I tell the program to deserialize the file up to "AllowChangeStartMenuFolderName" and then STOP?
- How do I tell the program to start deserializing at a certain point of an XML file(starting from the "entry" tag and down to the end of the file)?
Can somebody at least put me in the right direction, I haven't found any information on the internet. Thanks
EDIT
I have tried :
XmlTextReader reader = new XmlTextReader("...Path...\\data.xml");
//the last element before the keys and values of a hashtable start
reader.ReadToDescendant("AllowChangeStartMenuFolderName");
XmlSerializer serializer = new XmlSerializer(typeof(Classes.Information));
//info is a new empty object which should be filled with values from the XML file
this.info = (Classes.Information)serializer.Deserialize(reader.ReadSubtree());
reader.Close();
Throws me an exception at the last line - "Error in XML Document (27,4)".
My original XML (the first one was pseude code):
<?xml version="1.0" encoding="utf-8"?>
<Information xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CompileScript>false</CompileScript>
<SaveScript>false</SaveScript>
<ConvertPaths>false</ConvertPaths>
<UseUninstaller>true</UseUninstaller>
<UninstallSuccess>[NAME] was successfully removed from your computer.</UninstallSuccess>
<UninstallPrompt>Are you sure you want to completely remove [NAME] and all of its components?</UninstallPrompt>
<AllowChangeStartMenuFolderName>false</AllowChangeStartMenuFolderName>
<StartMenuShortcut>true</StartMenuShortcut>
<StartMenuUninstallIcon>true</StartMenuUninstallIcon>
<TheRightProgramFilesDirectoryUserView>Program Files (x86)</TheRightProgramFilesDirectoryUserView>
<RadioButtonRadioButton>false</RadioButtonRadioButton>
<CheckBoxRadioButton>false</CheckBoxRadioButton>
<ClassicButtonRadioButton>false</ClassicButtonRadioButton>
<AllowChangeDirectoryCheckBox>true</AllowChangeDirectoryCheckBox>
<ApplicationDirectory>C:\Program Files(x86)\ANNAX\My application</ApplicationDirectory>
<ApplicationName>My application</ApplicationName>
<ApplicationVersion>1.0</ApplicationVersion>
<ApplicationPublisher>My company, Inc.</ApplicationPublisher>
<ApplicationWebsite>http://wwww.mycompany.com</ApplicationWebsite>
<SetupIcon>Icons\modern-install.ico</SetupIcon>
<GermanCheckBox>false</GermanCheckBox>
<EnglishCheckBox>true</EnglishCheckBox>
<FrenchCheckBox>false</FrenchCheckBox>
<ThirtyTwoBitRadioButton>true</ThirtyTwoBitRadioButton>
<SixtyFourBitRadioButton>false</SixtyFourBitRadioButton>
<entry>
<fileName>file1</fileName>
<instDir>instDir1</instDir>
</entry>
<entry>
<fileName>file2</fileName>
<instDir>instDir2</instDir>
</entry>
<entry>
<fileName>file3</fileName>
<instDir>instDir3</instDir>
</entry>
<entry>
<fileName>file4</fileName>
<instDir>instDir4</instDir>
</entry>
<entry>
<fileName>file5</fileName>
<instDir>instDir5</instDir>
</entry>
<entry>
<fileName>file6</fileName>
<instDir>instDir6</instDir>
</entry>
<entry>
<fileName>file7</fileName>
<instDir>instDir7</instDir>
</entry>
<entry>
<fileName>file8</fileName>
<instDir>instDir8</instDir>
</entry>
<entry>
<fileName>file9</fileName>
<instDir>instDIr9</instDir>
</entry>