• Advertisement
Sign in to follow this  

[C#] Generic XML Parser

This topic is 2848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello All, I had made a 2D Point and click game a little while ago , the catch to it was that the game used to parse XML files to generate scenes, so the whole system was configurable and you could make new games just by editing the XML files. However I have come to realize that the way in which we did XML parsing was ... well ... stupid [:P] , basically we hard-coded each XML file structure into our program and then read data from XML fields into objects of the classes we had made (with the hard-coded structures). This method , I think is not scalable at all and is also increasing the code volume by a lot (there are any classes). I was wondering if there is any way to automatically parse and create objects from XML files themselves ? So that no data pertaining to the XML files ever needs to be coded into the program. Kinda lie a black box , into which you put an XML file and creates an (or more) objects for you with the names as given in the XML. EDIT : I think my initial post was a bit too ambiguous , I wanted to clarify something further, I DO NOT want the xml files to just be parsed and be left with the data in the files. I WANT : 1. The File to be parsed 2. The data to be fetched 3. Objects to be created using the tag names as in the XML eg. If my XML was <This_is_My_XML> <Attrib_1> </Attrib_1> <Attrib_2> <Attrib_3> </Attrib_3> </Attrib_2> </This_is_My_XML> Then I would want the Parsing system to create an object of type : This_is_My_XML which would have data members : Attrib_1 Attrib_2 (Which itself is an object of type Attrib_2 and has Attrib_3 as a data member) and so on. Is what I am saying even possible ? [Edited by - newbie8787 on April 2, 2010 1:40:01 AM]

Share this post


Link to post
Share on other sites
Advertisement
If you'd be using C++, I'd suggest using TinyXML (http://www.grinninglizard.com/tinyxml/). Of course you could make a library of it that you could use with C# if you feel adventurous. I don't work very often with C# and managed code but I think you are looking for System.XML (http://msdn.microsoft.com/en-us/library/system.xml(VS.71).aspx)

- Roxy

Share this post


Link to post
Share on other sites
I'm using XML for serialization also. To do this I have declared an interface ISerialize from which any class requiring can inherit. I use one XML file to list the required objects. When an object is required I make a call to it's relevant function DeserializeFromXML and give it it's own file to read. I use XMLLite(also c++) as my parser and am developing a static library of functions relevant to my application.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement