Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a XML file which is currently made manually and I have to make a functionality(UI) where user can enter the data and I have to store the data and generate the XML file dynamically in .NET.

Problem is the format of the XML file. I am not able to decide how I am going to store that data and then dynamically generate xml from that.

Please find the some of the extract of the code from the xml file below:
XML
<data>
  <sdacts>
    <sdact type="Economy" colour="0xff0000" />
    <sdact type="Environment" colour="0x00ff00" />
  </sdacts>
  <industries>
    <industry type="Platinum" colour="0x0094B1">
      <product>Platinum</product>
      <product>Palladium</product>
    </industry>
    <industry type="Diamonds" colour="0x652382">
      <product>Diamonds</product>
    </industry>
</industries>
  <locations>
    <continent title="South America">
      <country title="Brazil">
        <headoffice>So Paulo</headoffice>
        <address>
         Sau, polo, ambikaui
        </address>
        <latitude>-23.571157</latitude>
        <longitude>-46.644146</longitude>
        <businessunits>Nickel; Iron ore and manganese</businessunits>
        <description>Anglo American has been operating in Brazil since        1973.</description>
        <numberofbusiness>2</numberofbusiness>
        <!--New project added - 12/02/2010  start -->
        <project>
          <type>Greenfield</type>
          <name>Minas Rio expansion</name>
          <unittype>Iron Ore and Manganese</unittype>
          <relatedoperation>Greenfield</relatedoperation>
          <latitude>-18.92814</latitude>
          <longitude>-43.42562</longitude>
          <status>Future unapproved</status>
          <description />
          <fullproductiondate>TBD</fullproductiondate>
        </project>
        <sdactivity>
          <id>3.2.4.20</id>
          <type>Society</type>
          <business>Nickel</business>
          <relatedoperation />
          <heading>Listening - and acting - in Brazil</heading>
          <subheading>SEAT community engagement session in Brazil</subheading>
          <copy>
            local government.
          </copy>
          <image>3.2.4.20.jpg</image>
          <linkcaption>Read more about SEAT in Brazil</linkcaption>
          <linkurl>http://www.angloamerican.co.uk/aa/development/case-studies/society/society01/</linkurl>
        </sdactivity>
 </country>
   </continent>
  </locations>
</data>
Posted
Updated 27-Jun-10 20:52pm
v6

1 solution

This looks pretty complex, but you'll need to start by generating classes. Here's a short (incomplete) example:

Public Class Data

Public Property sdacts as New List(of sdact)
Public Property Industries as New List(of Industry)
Public Property Locations as New List(of Continent)

End Class


And keep making more classes as you go. Please note, the above example will only compile in Visual Studio 2010, you'll need to manually add the variables if you are using an earlier version.

If you are confused, look up some tutorials on classes, and look up List(Of T) .

Once you've done that, you'll want to investigate some tutorials on XML Serialization. This allows you to turn these classes into an XML file, with just a few lines of code, regardless of how much is in there.

Good luck! :)
 
Share this answer
 
Comments
angelvarun 28-Jun-10 4:39am    
@dawmail333- thanks for the suggested solution.In this case number of classes will increase as the xml has a healthy hierarchy. i was looking for some easy solution like getting the values from the UI and storing them in sql server db and then getting the xml using ds.getxml or ds.writexml....
dawmail333 28-Jun-10 5:00am    
Hmm, XML serialization only really likes items that it current expects, it has a problem with inherited objects (which is what I assume you are talking about). Sorry, I can't help you there, if that's the case.
angelvarun 28-Jun-10 5:33am    
No worries. I appreciate your efforts :)
dawmail333 28-Jun-10 6:15am    
You may want to clarify your question a little more then.
angelvarun 28-Jun-10 8:51am    
Here I get my answer :

http://support.microsoft.com/kb/317666

Now the challenge is how to make a UI which allows user to enter the values and attributes they want to add,remove, and modify.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900