Newtonsoft.Json JsonConvert to XmlDocument date formatting inconsistent when elements have attributes
<p>The <code>Newtonsoft.Json</code> libraries' <code>JsonConvert.DeserializeXmlNode</code> gives inconsistent datetime results when elements have attributes on them.</p>

<p>Here is a small example that demonstrates the issue</p>

<pre><code>public void Main(string[] args)
{
    var now = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss");
    var xml = $"&lt;timestamp&gt;{now}&lt;/timestamp&gt;";
    Debug.WriteLine(xml);
    // &lt;timestamp&gt;2016-11-14T14:51:32&lt;/timestamp&gt;
    var json = XmlToJson(xml);
    Debug.WriteLine(json);
    // {"timestamp":"2016-11-14T14:51:32"}
    var good = JsonToXml(json);
    Debug.WriteLine(good);
    // &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;timestamp&gt;2016-11-14T14:51:32&lt;/timestamp&gt;

    var xml_with_attr = $"&lt;timestamp id=\"1\"&gt;{now}&lt;/timestamp&gt;";
    Debug.WriteLine(xml_with_attr);
    // &lt;timestamp id="1"&gt;2016-11-14T14:51:32&lt;/timestamp&gt;
    var json_with_attr = XmlToJson(xml_with_attr);
    Debug.WriteLine(json_with_attr);
    // {"timestamp":{"@id":"1","#text":"2016-11-14T14:51:32"}}
    var bad = JsonToXml(json_with_attr);
    Debug.WriteLine(bad);
    // &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;timestamp id="1"&gt;2016-11-14 2:51:32 PM&lt;/timestamp&gt;
}

private string XmlToJson(string xml)
{

    var doc = new XmlDocument();
    doc.LoadXml(xml);
    var json = JsonConvert.SerializeXmlNode(doc);
    return json;
}
private string JsonToXml(string json)
{
    var doc = JsonConvert.DeserializeXmlNode(json);
    var xml = string.Empty;
    var settings = new XmlWriterSettings
    {
        CloseOutput = true,
        Encoding = Encoding.UTF8,
    };
    using (var ms = new MemoryStream())
    using (var xw = XmlWriter.Create(ms, settings))
    {
        doc.WriteTo(xw);
        xw.Flush();
        xml = settings.Encoding.GetString(ms.ToArray());
    }
    return xml;
}
</code></pre>

<p>As you can see, the <code>bad</code> date is not in the same format as all the previous results. This is unfortunately causing the xml to fail schema validation once it gets verified against the schema.</p>

<p>I know about the <code>DateTimeConverter</code> stuff, but converting to and from a XmlDocument does not give me that option.</p>

<p>I can also - unfortunately - not do the <code>JsonConvert</code> on the schema generated class because I have no idea what it might be at the time of execution.</p>

<p>Does anyone know how I can get the same format back when the element has an attribute?</p>

<p>Thanks</p>