code_junkie

Can XmlSerializer deserialize into a Nullable<int>?

Nov 12th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="array">
  3. <entity>
  4. <id xsi:type="integer">1</id>
  5. <name>Foo</name>
  6. <parent-id xsi:type="integer" xsi:nil="true"/>
  7.  
  8. public static void FixNilAttributeName(this XmlNode @this)
  9. {
  10. XmlAttribute nilAttribute = @this.Attributes["nil"];
  11. if (nilAttribute == null)
  12. {
  13. return;
  14. }
  15.  
  16. XmlAttribute newNil = @this.OwnerDocument.CreateAttribute("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance");
  17. newNil.Value = nilAttribute.Value;
  18. @this.Attributes.Remove(nilAttribute);
  19. @this.Attributes.Append(newNil);
  20. }
  21.  
  22. xmlStr = Regex.Replace(xmlStr, "nil="true"", "xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"");
Add Comment
Please, Sign In to add comment