Error in Deserialize an XML string

Error in Deserialize an XML string

ilovejingle
Enthusiast Enthusiast
348 Views
0 Replies
Message 1 of 1

Error in Deserialize an XML string

ilovejingle
Enthusiast
Enthusiast

I got an XML string from one of the customers

<AbstractConveyorModel i:type="ConveyorModelStraight" xmlns="http://schemas.datacontract.org/2004/07/BEUMERGroup.BESD.ACAD.AutoCADCommands.Conveyor.Model" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><BottomCover>No</BottomCover><Capacity>0</Capacity><Cascading>No</Cascading><EmergencyStop>No</EmergencyStop><Encoder>No</Encoder><FileName>Conveyors\BGH_CON_LLD_Mask-T1.dwg</FileName><Finish>Steel</Finish><FrequencyInverter>No</FrequencyInverter><Manufactures i:nil="true" xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/><MotorBrake>Yes</MotorBrake><MotorBrand>SEW</MotorBrand><MotorControllerMotorStarter>Motor starter</MotorControllerMotorStarter><MotorControllerPlacement>0</MotorControllerPlacement><MotorControllerSide>Left</MotorControllerSide><MotorPlacement>0</MotorPlacement><MotorPower>0.75</MotorPower><MotorRotation>0</MotorRotation><MotorSide>Left</MotorSide><Name>T1</Name><OilSump>No</OilSump><PhotoCell>No</PhotoCell><Reversible>No</Reversible><SideGuardAdjustment i:type="StraightAdjustment"><Head>145</Head><Tail>219</Tail></SideGuardAdjustment><SideGuardHeightLeft>400</SideGuardHeightLeft><SideGuardHeightRight>400</SideGuardHeightRight><Speed>0.5</Speed><StandardName>BGH</StandardName><Tracking>No</Tracking><Width>1000</Width><_sideguardOpenings i:nil="true"/><Length>1200</Length></AbstractConveyorModel>

What I want to do is to deserialize this xml string to my own object. 

I created an object like this

    public class myInfo
    {
        public string Name { get; set; }
        public double Length { get; set; }
        public string MotorSide { get; set; }
        public double MotorPlacement { get; set; }
    }

 

It contains only few attributes which is relevant to me, When I try to deserialize it, an error occured. 

 

var serializer = new XmlSerializer(typeof(myInfo));
myInfo info;
using (TextReader reader = new StringReader(str))
{
    info = (myInfo)serializer.Deserialize(reader);
}

 

Can I actually do this? Thank you very much.  

0 Likes
349 Views
0 Replies
Replies (0)