Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Write WCF XML Message to Dictionary
  2. <data>
  3.   <name>Jim</name>
  4.   <age>28</age>
  5.   <location>London</location>
  6. </data>
  7.        
  8. [DataContract(Namespace="",Name="data")]
  9. public class Data
  10. {
  11.     [DataMember(Name = "name")]
  12.     public string Name;
  13.     [DataMember(Name = "age")]
  14.     public string Age;
  15.     [DataMember(Name = "location")]
  16.     public string Location;
  17.  
  18. }
  19.        
  20. <dict>
  21.   <key>Name</key>
  22.   <string>Jim</string>
  23.   <key>Age</key>
  24.   <string>28</string>
  25.   <key>Location</key>
  26.   <data>London</data>
  27. </dict>
  28.        
  29. var oldMessage = XDocument.Parse(message_string);
  30. var newMessage = new XDocument(new XElement("data",
  31.     oldMessage.Root.Elements("key").Select(el =>
  32.         new XElement(el.Value.ToLower(),
  33.             el.ElementsAfterSelf().First().Value))));