c# - Impossible? How to deserialize this using DataContractSerializer? -


so have xml looks this:

<a>     <b c="1" ></b>     <b c="2" ></b>     <b c="3" ></b>     <b c="4" ></b> </a> 

i want deserialize on wp7 using datacontractserializerdo that.

i run across opinions impossible without tricks enclosing xml in additional tags push < > down root level.
true?

on request i'm adding code

classes:

[knowntype(typeof(b))] [datacontract(namespace = "")] public class a:list<b> {     [datamember]     public list<b> b     {         list<b> _b = new list<b>();         { return _b; }         set { _b = value; }     } }  [datacontract(namespace = "")] public class b {     [datamember]     public string c = "foo"; } 

deserialisation:

var serializer = new datacontractserializer(typeof(a)); var o = serializer.readobject(someresponsestream); 

and many, many other variations of this.
way - arrangement of classes serialized xml this:

<a>     <b>         <b c="1" ></b>         <b c="2" ></b>         <b c="3" ></b>         <b c="4" ></b>     </b> </a> 

notice additional, unwanted level of < b >

as said in comments, linq2xml can better way go

string xml = @" <a>     <b>         <b c=""1"" ></b>         <b c=""2"" ></b>         <b c=""3"" ></b>         <b c=""4"" ></b>     </b> </a>";  var bs = xdocument.parse(xml)                     .root                     .element("b")                     .elements("b")                     .select(b => new b { c = b.attribute("c").value })                     .tolist(); 

.

public class b {     public string c = "foo"; } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -