so have xml url looks this:
<restaurantfoodimpls> <restaurantfood price="1689.7594" id="426" description="quis egreddior glavans brevens, si eggredior. vobis e fecundio, fecundio, et quoque nomen gravum parte volcans"> <fooditem name="frances93" id="548"/> <restaurant name="alana59" phonenumber="7954016342" mobilenumber="372206-3626" lastname="hickman" id="1" firstname="gabrielle"/> </restaurantfood> <restaurantfood price="14.225095" id="520" description="in plorum egreddior plorum e pladior in linguens essit. novum habitatio versus plurissimum volcans linguens estum."> <fooditem name="frances93" id="548"/> <restaurant name="alana59" phonenumber="7954016342" mobilenumber="372206-3626" lastname="hickman" id="1" firstname="gabrielle"/> </restaurantfood> </restaurantfoodimpls>
how parse objects using c#?
have tried using deserializer problem want properties of elements read attributes in xml, , couldn't them.
var stream = file.open(filename, filemode.open); xmlserializer ser = new xmlserializer(typeof(restaurantfoodimpls)); var result = ser.deserialize(stream) restaurantfoodimpls;
public class fooditem { [xmlattribute] public string name { get; set; } [xmlattribute] public string id { get; set; } } public class restaurant { [xmlattribute] public string name { get; set; } [xmlattribute] public string phonenumber { get; set; } [xmlattribute] public string mobilenumber { get; set; } [xmlattribute] public string lastname { get; set; } [xmlattribute] public string id { get; set; } [xmlattribute] public string firstname { get; set; } } public class restaurantfood { [xmlattribute] public string price { get; set; } [xmlattribute] public string id { get; set; } [xmlattribute] public string description { get; set; } [xmlelement("fooditem")] public fooditem fooditem { get; set; } [xmlelement("restaurant")] public restaurant restaurant { get; set; } } [xmlroot("restaurantfoodimpls")] public class restaurantfoodimpls { [xmlelement("restaurantfood")] public list<restaurantfood> restaurantfood { get; set; } }
Comments
Post a Comment