Home All Groups Group Topic Archive Search About

Reads XML node from App.Config and populates a Class

Author
9 Mar 2006 4:36 PM
PH
Hi guys;



I got the following problem to solve, hope you can help me.



I got a XML node in App.Conf;





<CUSTOMERS>

<CUSTOMER>

<NAME =”Frank” />

<LASTNAME =”Smith”/>

<AGE= 34 />

</CUSTOMER>



<CUSTOMER>

<NAME =”Lisa” />

<LASTNAME =”Tucker”/>

<AGE= 42 />

</CUSTOMER>

<CUSTOMERS/>



I will like to populate a class called Customers that has the same
structure than the XML node Customers, with all the Customer nodes.

Is there any automated way to do this in the framework?



Thanks very much

Author
9 Mar 2006 4:44 PM
Martin Honnen
PH wrote:


> I got a XML node in App.Conf;

> <CUSTOMERS>
>
> <CUSTOMER>
>
> <NAME =”Frank” />

That is not well-formed XML at all, you can either have
   <CUSTOMER NAME="Frank" />
or
   <CUSTOMER>
     <NAME>Frank</NAME>

> I will like to populate a class called Customers that has the same
> structure than the XML node Customers, with all the Customer nodes.
>
> Is there any automated way to do this in the framework?

You can use the xsd.exe tool to infer a schema and generate a class, see
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpconXMLSchemaDefinitionToolXsdexe.asp>

--

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/
Are all your drivers up to date? click for free checkup

Author
9 Mar 2006 6:16 PM
Ignacio Machin ( .NET/ C# MVP )
Hi,


Why you use app.config?
This file should content only the needed configuration for your app, no data.

You can keep your data in a XML file that can be readed direcly in a dataset.



--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


  "PH" <nospam@nospam.com> wrote in message news:001401c64397$a4b64850$0c01a8c0@m1...
  Hi guys;



  I got the following problem to solve, hope you can help me.



  I got a XML node in App.Conf;





  <CUSTOMERS>

  <CUSTOMER>

  <NAME ="Frank" />

  <LASTNAME ="Smith"/>

  <AGE= 34 />

  </CUSTOMER>



  <CUSTOMER>

  <NAME ="Lisa" />

  <LASTNAME ="Tucker"/>

  <AGE= 42 />

  </CUSTOMER>

  <CUSTOMERS/>



  I will like to populate a class called Customers that has the same structure than the XML node Customers, with all the Customer nodes.

  Is there any automated way to do this in the framework?



  Thanks very much
Author
9 Mar 2006 6:41 PM
PH
You’re right.

It will be a XML file.



Now, I want to populate a Class instead of a Dataset.



Thanks



  _____

From: Ignacio Machin ( .NET/ C# MVP ) [mailto:ignacio.machin AT
dot.state.fl.us]
Posted At: Thursday, March 09, 2006 1:17 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Reads XML node from App.Config and populates a Class
Subject: Re: Reads XML node from App.Config and populates a Class


Hi,





Why you use app.config?

This file should content only the needed configuration for your app, no
data.



You can keep your data in a XML file that can be readed direcly in a
dataset.






--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation





"PH" <nospam@nospam.com> wrote in message
news:001401c64397$a4b64850$0c01a8c0@m1...

Hi guys;



I got the following problem to solve, hope you can help me.



I got a XML node in App.Conf;





<CUSTOMERS>

<CUSTOMER>

<NAME =”Frank” />

<LASTNAME =”Smith”/>

<AGE= 34 />

</CUSTOMER>



<CUSTOMER>

<NAME =”Lisa” />

<LASTNAME =”Tucker”/>

<AGE= 42 />

</CUSTOMER>

<CUSTOMERS/>



I will like to populate a class called Customers that has the same
structure than the XML node Customers, with all the Customer nodes.

Is there any automated way to do this in the framework?



Thanks very much
Author
9 Mar 2006 9:04 PM
Ignacio Machin ( .NET/ C# MVP )
Hi,

What about a typed dataset?

If not you would have to create the method to populate the collection of Customers , there is nothing in the framework to do that for you.


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

  "PH" <nospam@nospam.com> wrote in message news:003601c643a9$0e595f70$0c01a8c0@m1...


  You're right.

  It will be a XML file.



  Now, I want to populate a Class instead of a Dataset.



  Thanks




------------------------------------------------------------------------------

  From: Ignacio Machin ( .NET/ C# MVP ) [mailto:ignacio.machin AT dot.state.fl.us]
  Posted At: Thursday, March 09, 2006 1:17 PM
  Posted To: microsoft.public.dotnet.languages.csharp
  Conversation: Reads XML node from App.Config and populates a Class
  Subject: Re: Reads XML node from App.Config and populates a Class


  Hi,





  Why you use app.config?

  This file should content only the needed configuration for your app, no data.



  You can keep your data in a XML file that can be readed direcly in a dataset.






  --
  Ignacio Machin,
  ignacio.machin AT dot.state.fl.us
  Florida Department Of Transportation





    "PH" <nospam@nospam.com> wrote in message news:001401c64397$a4b64850$0c01a8c0@m1...

    Hi guys;



    I got the following problem to solve, hope you can help me.



    I got a XML node in App.Conf;





    <CUSTOMERS>

    <CUSTOMER>

    <NAME ="Frank" />

    <LASTNAME ="Smith"/>

    <AGE= 34 />

    </CUSTOMER>



    <CUSTOMER>

    <NAME ="Lisa" />

    <LASTNAME ="Tucker"/>

    <AGE= 42 />

    </CUSTOMER>

    <CUSTOMERS/>



    I will like to populate a class called Customers that has the same structure than the XML node Customers, with all the Customer nodes.

    Is there any automated way to do this in the framework?



    Thanks very much
Author
9 Mar 2006 9:27 PM
PH
Ok I might use that.

Thanks Igancio.





  _____

From: Ignacio Machin ( .NET/ C# MVP ) [mailto:ignacio.machin AT
dot.state.fl.us]
Posted At: Thursday, March 09, 2006 4:05 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Reads XML node from App.Config and populates a Class
Subject: Re: Reads XML node from App.Config and populates a Class


Hi,



What about a typed dataset?



If not you would have to create the method to populate the collection of
Customers , there is nothing in the framework to do that for you.




--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



"PH" <nospam@nospam.com> wrote in message
news:003601c643a9$0e595f70$0c01a8c0@m1...



You’re right.

It will be a XML file.



Now, I want to populate a Class instead of a Dataset.



Thanks




  _____


From: Ignacio Machin ( .NET/ C# MVP ) [mailto:ignacio.machin AT
dot.state.fl.us]
Posted At: Thursday, March 09, 2006 1:17 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Reads XML node from App.Config and populates a Class
Subject: Re: Reads XML node from App.Config and populates a Class


Hi,





Why you use app.config?

This file should content only the needed configuration for your app, no
data.



You can keep your data in a XML file that can be readed direcly in a
dataset.






--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation





"PH" <nospam@nospam.com> wrote in message
news:001401c64397$a4b64850$0c01a8c0@m1...

Hi guys;



I got the following problem to solve, hope you can help me.



I got a XML node in App.Conf;





<CUSTOMERS>

<CUSTOMER>

<NAME =”Frank” />

<LASTNAME =”Smith”/>

<AGE= 34 />

</CUSTOMER>



<CUSTOMER>

<NAME =”Lisa” />

<LASTNAME =”Tucker”/>

<AGE= 42 />

</CUSTOMER>

<CUSTOMERS/>



I will like to populate a class called Customers that has the same
structure than the XML node Customers, with all the Customer nodes.

Is there any automated way to do this in the framework?



Thanks very much
Author
9 Mar 2006 10:41 PM
PH
XML Serialization is what I’m looking for.

http://msdn.microsoft.com/library/?url=/library/en-us/cpguide/html/cpcon
serialization.asp



Thanks to all who’ve respond.





  _____

From: PH [mailto:nospam@nospam.com]
Posted At: Thursday, March 09, 2006 4:28 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Reads XML node from App.Config and populates a Class
Subject: Re: Reads XML node from App.Config and populates a Class


Ok I might use that.

Thanks Igancio.





  _____

From: Ignacio Machin ( .NET/ C# MVP ) [mailto:ignacio.machin AT
dot.state.fl.us]
Posted At: Thursday, March 09, 2006 4:05 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Reads XML node from App.Config and populates a Class
Subject: Re: Reads XML node from App.Config and populates a Class


Hi,



What about a typed dataset?



If not you would have to create the method to populate the collection of
Customers , there is nothing in the framework to do that for you.




--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



"PH" <nospam@nospam.com> wrote in message
news:003601c643a9$0e595f70$0c01a8c0@m1...



You’re right.

It will be a XML file.



Now, I want to populate a Class instead of a Dataset.



Thanks




  _____


From: Ignacio Machin ( .NET/ C# MVP ) [mailto:ignacio.machin AT
dot.state.fl.us]
Posted At: Thursday, March 09, 2006 1:17 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Reads XML node from App.Config and populates a Class
Subject: Re: Reads XML node from App.Config and populates a Class


Hi,





Why you use app.config?

This file should content only the needed configuration for your app, no
data.



You can keep your data in a XML file that can be readed direcly in a
dataset.






--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation





"PH" <nospam@nospam.com> wrote in message
news:001401c64397$a4b64850$0c01a8c0@m1...

Hi guys;



I got the following problem to solve, hope you can help me.



I got a XML node in App.Conf;





<CUSTOMERS>

<CUSTOMER>

<NAME =”Frank” />

<LASTNAME =”Smith”/>

<AGE= 34 />

</CUSTOMER>



<CUSTOMER>

<NAME =”Lisa” />

<LASTNAME =”Tucker”/>

<AGE= 42 />

</CUSTOMER>

<CUSTOMERS/>



I will like to populate a class called Customers that has the same
structure than the XML node Customers, with all the Customer nodes.

Is there any automated way to do this in the framework?



Thanks very much

Bookmark and Share