XML - class in C# Options
vonlinaa
Posted: Sunday, October 29, 2006 7:19:26 PM
Rank: Aficionado

Joined: 7/23/2006
Posts: 172
I'm trying to make a class in c# where I get info from a xml doc.

the structure is like
<DeliveryOrderline>
<orderline country="Danmark">
<productId>ID</productId>
<productName>name</productName>
<price>40</price>
<quantity>1</quantity>
</orderline >

<orderline country="Greenland">
<productId>ID</productId>
<productName>name</productName>
<price>125</price>
<quantity>1</quantity>
</orderline>
</DeliveryOrderline>

I want the class to lookup the contry and write the price.

I'm stuck - what do I do.

Søren Linaa
Level 1 & 2 Certified Professional
Simm
Posted: Sunday, October 29, 2006 11:46:17 PM

Rank: Fanatic

Joined: 7/22/2006
Posts: 255
Location: Randers, Denmark
Hi Søren,

This is probably a generic C# programming question than Umbraco-specific .. It's actually simpler than you might think.. Try to look at this page: http://support.microsoft.com/kb/307548



Best Regards
Simon

Simm.dk - My base on the web - proud Umbracian since 2.0 Beta
vonlinaa
Posted: Monday, October 30, 2006 12:17:45 AM
Rank: Aficionado

Joined: 7/23/2006
Posts: 172
Well yes I think so too.
But with so many clever brains in here I took the chance on posting

Søren Linaa
Level 1 & 2 Certified Professional
Simm
Posted: Monday, October 30, 2006 12:35:37 AM

Rank: Fanatic

Joined: 7/22/2006
Posts: 255
Location: Randers, Denmark
I hope the above-mentioned link can help you, otherwise we can take a look at your problem again later ;)

Best Regards
Simon

Simm.dk - My base on the web - proud Umbracian since 2.0 Beta
neehouse
Posted: Monday, October 30, 2006 4:33:07 AM

Rank: Umbracoholic

Joined: 7/20/2006
Posts: 1,074
Location: Charleston, West Virginia, United States
Soren,

How are you planning on getting the country in the first place? Is it a value set from the user, or is it determined via a different means?

Beyond that, you could read the XML file into an XSLT, pull the country setting, and xpath the value you are wanting easily. Give me some more details, and I will try to guide you through some options.

Case

• 2007/2008 MVP • 2008/2009 MVP • Certified • Licensing • Support • Development • Hosting •
hoehler
Posted: Monday, October 30, 2006 8:21:39 AM

Rank: Addict

Joined: 7/19/2006
Posts: 597
Location: Bad Homburg, Germany
If you have a xsd you can let the xsd.exe create classes for you. Then you can get the structure via de/serialization:
Code:

_Ser = New XmlSerializer(GetType(YOUROBJECTTYPE))
Dim fs As FileStream = New FileStream(FILEPATH, FileMode.Open)
YOUROBJECT = CType(_Ser.Deserialize(fs), YOUROBJECTTYPE)

Thomas

• 2007/2008 MVP • www.thoehler.com • Bad Homburg, Germany
vonlinaa
Posted: Monday, October 30, 2006 12:04:23 PM
Rank: Aficionado

Joined: 7/23/2006
Posts: 172
I use the ecommerce project for Umbraco.
I have made some modifacations and I have a usercontrol where I get the country from a dropdown.
So I need to make the control in a c# class. Not XSLT in umbraco and I don't use VB.


Søren Linaa
Level 1 & 2 Certified Professional
hoehler
Posted: Monday, October 30, 2006 12:51:03 PM

Rank: Addict

Joined: 7/19/2006
Posts: 597
Location: Bad Homburg, Germany
Sorry for posting VB code, but it is simply to convert. If you don't get into it send me your schema or the structure of the file (th AT famhoehler dot de). I will then generate you the code.

Thomas

• 2007/2008 MVP • www.thoehler.com • Bad Homburg, Germany
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.