Reads XML node from App.Config and populates a Class

P

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
 
M

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>
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/d...s/html/cpconXMLSchemaDefinitionToolXsdexe.asp>
 
I

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


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
 
P

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






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
 
I

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



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






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
 
P

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






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






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
 
P

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:[email protected]]
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






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






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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top