none
DeSerializing XML data to an object RRS feed

  • Question

  • Hello All,

    I want to serialize below XML into an object.

    <import>
    	<node action="create" type="project">
    		<created><![CDATA[20121221113501]]></created>
    		<createdby><![CDATA[Admin]]></createdby>
    		<description clear="true"></description>
    		<goals clear="true"></goals>
    		<include_participants><![CDATA[false]]></include_participants>
    		<initiatives clear="true"></initiatives>
    		<location><![CDATA[MMP]]></location>
    		<modified><![CDATA[20130110100156]]></modified>
    		<objectives clear="true"></objectives>
    		
    		<roles>
    			<coordinator type="user"><![CDATA[ABC]]></coordinator>
    			<guest type="group"><![CDATA[KBC-All]]></guest>
    			<member type="group"><![CDATA[KBN-PPT]]></member>
    		</roles>
    		<startdate><![CDATA[20121221113501]]></startdate>
    		<status><![CDATA[Pending]]></status>
    		<title><![CDATA[Loaded]]></title>
    	</node>
    <node action="create" type="document">
    		<acl permissions="454545454" role="Members"></acl>
    		
    		<acl baseowner="KJNH" permissions="111111111"></acl>		
    		<category name="My Categories:CCD">
    			<attribute name="Status"><![CDATA[POSTPONE]]></attribute>
    			<attribute name="Effective Date"><![CDATA[20130308]]></attribute>
    			
    			<attribute clear="true" name="PPB"></attribute>			
    			<setattribute name="Function">
    				<attribute name="Function"><![CDATA[gdfr]]></attribute>
    				<attribute clear="true" name="Sub-Function"></attribute>
    			</setattribute>
    			
    		</category>
    		
    		<category name="My Categories:Information">
    			<attribute name="Author"><![CDATA[KIO]]></attribute>
    		</category>
    	
    		<created><![CDATA[20130308085536]]></created>
    	</node>
    </import>

    Please guide me how do I design classes with XML attribute & XML elements so that they get deserialise to an object once I load the XML. Can you please share sample code for this

    Any help is greatly appreciated.

    Thanks, Alex


    AC


    • Edited by Alex Cardo Monday, September 7, 2015 11:45 AM
    Monday, September 7, 2015 11:43 AM

Answers

  • I want to serialize below XML into an object.

    You make concrete classes/objects. 

    https://msdn.microsoft.com/en-us/library/bb384054.aspx?f=255&MSPPError=-2147217396

    You can use Linq-2-XML.

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=564

    You can use a Linq projection to project the results into a concrete class/object. 

    http://www.csharp-station.com/Tutorial/Linq/Lesson02

    Or you can use Xpath and populate a concrete class/object

    https://msdn.microsoft.com/en-us/library/3tk3f03k(v=vs.110).aspx

    Monday, September 7, 2015 5:46 PM