.net - Deserialization of key value pair in XML to c# object -


I have XML as shown below.

  & lt; Device-array & gt; & Lt; Device & gt; & Lt; ID & gt; 8 & lt; / Id & gt; & Lt; Properties & gt; & Lt; PropKeyValuePair & gt; ... & lt; / PropKeyValuePair & gt; & Lt; PropKeyValuePair & gt; ... & lt; / PropKeyValuePair & gt; & Lt; / Properties & gt; & Lt; / Tools & gt; & Lt; Device & gt; ... & lt; / Tools & gt; & Lt; Device & gt; ... & lt; / Tools & gt; & Lt; / Device-array & gt;   

I plan to distribute it to the C # object so that it can be done faster. I just need an id area but I think there is an array required for class (properties) but how can I represent important value verb?

  [serialable] Public class SLV jioojone {[XML ("ID")] public string id {get; Set; } // Important value pairs entries here? }   

requires suggetions

You can use LINQ in XML instead of Deserialization and just get what you need: ID of List:

  var xDoc = XDocument.Load ("FilePath.xml"); Var IDs = xDoc.Root .Elements ("Device"). Select (x = & gt; (int) x.Element ("id").) Catalog ();   

If you really need to use deserialization then you can only exclude those properties that you do not need and XmlSerializer deserialize only the declared content

Update

and except for those elements which you have not declared in your class, to get just one name in the list of anonymous type : Select

  var ID = (string) x.Element ("name")}. .to list();    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -