Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to deserialize not standard datetime in xml
    text
    copied!<p>I am trying to deserialize some response I got back from a service call. However, the response contains some datetime format thats not standard. Its throwing The string '13:37:53 Feb 29, 2012 PST' is not a valid AllXsd value. I am wondering if there is way I can change my xmlreader or something so I can deserialize this?</p> <pre><code>&lt;TimeCreated xsi:type="xs:dateTime"&gt;13:37:53 Feb 29, 2012 PST&lt;/TimeCreated&gt; &lt;TimeUpdated xsi:type="xs:dateTime"&gt;13:37:53 Feb 29, 2012 PST&lt;/TimeUpdated&gt; </code></pre> <p>This is the code I am using to deserialize. </p> <pre><code> public static T DeserializeFromXml&lt;T&gt;(string xml) { T result; XmlSerializer serializer = new XmlSerializer(typeof(T)); using (TextReader txReader = new StringReader(xml)) { // Create XmlReaderSettings XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; settings.IgnoreWhitespace = true; settings.IgnoreComments = true; // Create a new NameTable NameTable nt = new NameTable(); // Create a new NamespaceManager XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); // Add your namespaces used in the XML nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); // Create the XmlParserContext using the previous declared XmlNamespaceManager XmlParserContext ctx = new XmlParserContext(null, nsmgr, null, XmlSpace.None); // Instantiate a new XmlReader, using the previous declared XmlReaderSettings and XmlParserContext XmlReader reader = XmlReader.Create(txReader, settings, ctx); result = (T)serializer.Deserialize(reader); } return result; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload