c# - Deserializing XML where elements and attributes have duplicate names -


i want deserialize following xml. problem duplicate element names , attribute names. have tried apporach deserializing duplicate xml elements unique attributes

but keep getting.: "account xmlns='' not expected."

<?xml version="1.0" encoding="utf-8"?> <account>   <field apiname="wrntyid">1234</field>   <field apiname="externalid">4321</field>   <field apiname="creationdate">07/04/2015 18:28:45</field>   <field apiname="name"></field>   <field apiname="phone"></field>   <field apiname="mobile"></field>   <field apiname="fax"></field>   <field apiname="email"></field>   <field apiname="govid"></field>   <field apiname="note"></field>   <field apiname="isactive">true</field>   <field apiname="connectedtosuperbiz">false</field>   <field apiname="street"></field>   <field apiname="city"></field>   <field apiname="state"></field>   <field apiname="country">usa</field>   <field apiname="zipcode">33172</field>   <field apiname="discount">0</field>   <field apiname="pricelevelname">usd</field>   <field apiname="prop1"></field>   <field apiname="prop2"></field>   <field apiname="prop3"></field>   <field apiname="prop4"></field>   <field apiname="prop5"></field>   <agents>     <agent>       <field apiname="wrntyid">54321</field>       <field apiname="externalid"></field>     </agent>   </agents>   <catalogs>     <catalog>       <field apiname="wrntyid">12345</field>       <field apiname="externalid"></field>     </catalog>   </catalogs>   <locations>     <location>       <field apiname="wrntyid">123456</field>       <field apiname="externalid">0002</field>     </location>   </locations>   <contacts>     <contact>       <field apiname="wrntyid">1234</field>       <field apiname="externalid"></field>     </contact>   </contacts> </account> 

my c# classes now.:

[xmlroot]     public class account {                 public agents agents { get; set; }         public catalogs catalogs { get; set; }         public locations locations { get; set; }         public contacts contacts { get; set; }     }     public class agents {         [xmlarray("agent")]         [xmlarrayitem("field", typeof(values))]         public values[] field { get; set; }     }     public class catalogs {         [xmlarray("catalog")]         [xmlarrayitem("field", typeof(values))]         public values[] field { get; set; }     }     public class contacts {         [xmlarray("contact")]         [xmlarrayitem("field", typeof(values))]         public values[] field { get; set; }     }     public class locations {         [xmlarray("location")]         [xmlarrayitem("field", typeof(values))]         public values[] field { get; set; }     }     public class values {         [xmlattribute("apiname")]         public string apiname { get; set; }         [xmltext]         public string value { get; set; }     }   

(i have ommited of classes readability sake) big question this, there different way of deserializing c# obj or proper approach mapping manually?

edit added revised class structure, can me on how structure classes? not sure on how handle the field=apiname elements in account?

you don't provide namespace in xml file.

xmlrootattribute defaults to: xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" if no custom namespace provided.

try telling xmlreader not use namespaces

 xmlreader reader = new xmlreader() { namespaces = false }; 

but: recommend using specific namespaces files!


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -