~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/Newtonsoft.Json/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
ļ»æ#region License
 
2
// Copyright (c) 2007 James Newton-King
 
3
//
 
4
// Permission is hereby granted, free of charge, to any person
 
5
// obtaining a copy of this software and associated documentation
 
6
// files (the "Software"), to deal in the Software without
 
7
// restriction, including without limitation the rights to use,
 
8
// copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
// copies of the Software, and to permit persons to whom the
 
10
// Software is furnished to do so, subject to the following
 
11
// conditions:
 
12
//
 
13
// The above copyright notice and this permission notice shall be
 
14
// included in all copies or substantial portions of the Software.
 
15
//
 
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
17
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
18
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
19
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
20
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
21
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
23
// OTHER DEALINGS IN THE SOFTWARE.
 
24
#endregion
 
25
 
 
26
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
 
27
using System;
 
28
using System.Collections.Generic;
 
29
using Newtonsoft.Json.Tests.Serialization;
 
30
using Newtonsoft.Json.Tests.TestObjects;
 
31
#if !NETFX_CORE
 
32
using NUnit.Framework;
 
33
#else
 
34
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
 
35
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
 
36
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
 
37
#endif
 
38
using Newtonsoft.Json;
 
39
using System.IO;
 
40
using System.Xml;
 
41
using Newtonsoft.Json.Converters;
 
42
using Newtonsoft.Json.Utilities;
 
43
using Newtonsoft.Json.Linq;
 
44
#if !NET20
 
45
using System.Xml.Linq;
 
46
#endif
 
47
 
 
48
namespace Newtonsoft.Json.Tests.Converters
 
49
{
 
50
  [TestFixture]
 
51
  public class XmlNodeConverterTest : TestFixtureBase
 
52
  {
 
53
    private string SerializeXmlNode(XmlNode node)
 
54
    {
 
55
      string json = JsonConvert.SerializeXmlNode(node, Formatting.Indented);
 
56
      XmlNodeReader reader = new XmlNodeReader(node);
 
57
 
 
58
#if !NET20
 
59
      XObject xNode;
 
60
      if (node is XmlDocument)
 
61
      {
 
62
        xNode = XDocument.Load(reader);
 
63
      }
 
64
      else if (node is XmlAttribute)
 
65
      {
 
66
        XmlAttribute attribute = (XmlAttribute) node;
 
67
        xNode = new XAttribute(XName.Get(attribute.LocalName, attribute.NamespaceURI), attribute.Value);
 
68
      }
 
69
      else
 
70
      {
 
71
        reader.MoveToContent();
 
72
        xNode = XNode.ReadFrom(reader);
 
73
      }
 
74
 
 
75
      string linqJson = JsonConvert.SerializeXNode(xNode, Formatting.Indented);
 
76
 
 
77
      Assert.AreEqual(json, linqJson);
 
78
#endif
 
79
 
 
80
      return json;
 
81
    }
 
82
 
 
83
    private XmlNode DeserializeXmlNode(string json)
 
84
    {
 
85
      return DeserializeXmlNode(json, null);
 
86
    }
 
87
 
 
88
    private XmlNode DeserializeXmlNode(string json, string deserializeRootElementName)
 
89
    {
 
90
      JsonTextReader reader;
 
91
 
 
92
      reader = new JsonTextReader(new StringReader(json));
 
93
      reader.Read();
 
94
      XmlNodeConverter converter = new XmlNodeConverter();
 
95
      if (deserializeRootElementName != null)
 
96
        converter.DeserializeRootElementName = deserializeRootElementName;
 
97
 
 
98
      XmlNode node = (XmlNode)converter.ReadJson(reader, typeof (XmlDocument), null, new JsonSerializer());
 
99
 
 
100
#if !NET20
 
101
     string xmlText = node.OuterXml;
 
102
 
 
103
      reader = new JsonTextReader(new StringReader(json));
 
104
      reader.Read();
 
105
      XDocument d = (XDocument) converter.ReadJson(reader, typeof (XDocument), null, new JsonSerializer());
 
106
 
 
107
      string linqXmlText = d.ToString(SaveOptions.DisableFormatting);
 
108
      if (d.Declaration != null)
 
109
        linqXmlText = d.Declaration + linqXmlText;
 
110
 
 
111
      Assert.AreEqual(xmlText, linqXmlText);
 
112
#endif
 
113
 
 
114
      return node;
 
115
    }
 
116
 
 
117
#if !NET20
 
118
    [Test]
 
119
    public void SerializeEmptyDocument()
 
120
    {
 
121
      XmlDocument doc = new XmlDocument();
 
122
      doc.LoadXml("<root />");
 
123
 
 
124
      string json = JsonConvert.SerializeXmlNode(doc, Formatting.Indented, true);
 
125
      Assert.AreEqual("null", json);
 
126
 
 
127
      doc = new XmlDocument();
 
128
      doc.LoadXml("<root></root>");
 
129
 
 
130
      json = JsonConvert.SerializeXmlNode(doc, Formatting.Indented, true);
 
131
      Assert.AreEqual("null", json);
 
132
 
 
133
 
 
134
      XDocument doc1 = XDocument.Parse("<root />");
 
135
 
 
136
      json = JsonConvert.SerializeXNode(doc1, Formatting.Indented, true);
 
137
      Assert.AreEqual("null", json);
 
138
 
 
139
      doc1 = XDocument.Parse("<root></root>");
 
140
 
 
141
      json = JsonConvert.SerializeXNode(doc1, Formatting.Indented, true);
 
142
      Assert.AreEqual("null", json);
 
143
    }
 
144
#endif
 
145
 
 
146
    [Test]
 
147
    public void DocumentSerializeIndented()
 
148
    {
 
149
      string xml = @"<?xml version=""1.0"" standalone=""no""?>
 
150
<?xml-stylesheet href=""classic.xsl"" type=""text/xml""?>
 
151
<span class=""vevent"">
 
152
  <a class=""url"" href=""http://www.web2con.com/"">
 
153
    <span class=""summary"">Web 2.0 Conference<![CDATA[my escaped text]]></span>
 
154
    <abbr class=""dtstart"" title=""2005-10-05"">October 5</abbr>
 
155
    <abbr class=""dtend"" title=""2005-10-08"">7</abbr>
 
156
    <span class=""location"">Argent Hotel, San Francisco, CA</span>
 
157
  </a>
 
158
</span>";
 
159
      XmlDocument doc = new XmlDocument();
 
160
      doc.LoadXml(xml);
 
161
 
 
162
      string jsonText = SerializeXmlNode(doc);
 
163
      string expected = @"{
 
164
  ""?xml"": {
 
165
    ""@version"": ""1.0"",
 
166
    ""@standalone"": ""no""
 
167
  },
 
168
  ""?xml-stylesheet"": ""href=\""classic.xsl\"" type=\""text/xml\"""",
 
169
  ""span"": {
 
170
    ""@class"": ""vevent"",
 
171
    ""a"": {
 
172
      ""@class"": ""url"",
 
173
      ""@href"": ""http://www.web2con.com/"",
 
174
      ""span"": [
 
175
        {
 
176
          ""@class"": ""summary"",
 
177
          ""#text"": ""Web 2.0 Conference"",
 
178
          ""#cdata-section"": ""my escaped text""
 
179
        },
 
180
        {
 
181
          ""@class"": ""location"",
 
182
          ""#text"": ""Argent Hotel, San Francisco, CA""
 
183
        }
 
184
      ],
 
185
      ""abbr"": [
 
186
        {
 
187
          ""@class"": ""dtstart"",
 
188
          ""@title"": ""2005-10-05"",
 
189
          ""#text"": ""October 5""
 
190
        },
 
191
        {
 
192
          ""@class"": ""dtend"",
 
193
          ""@title"": ""2005-10-08"",
 
194
          ""#text"": ""7""
 
195
        }
 
196
      ]
 
197
    }
 
198
  }
 
199
}";
 
200
 
 
201
      Assert.AreEqual(expected, jsonText);
 
202
 
 
203
      Console.WriteLine("DocumentSerializeIndented");
 
204
      Console.WriteLine(jsonText);
 
205
      Console.WriteLine();
 
206
    }
 
207
 
 
208
    [Test]
 
209
    public void SerializeNodeTypes()
 
210
    {
 
211
      XmlDocument doc = new XmlDocument();
 
212
      string jsonText;
 
213
 
 
214
      Console.WriteLine("SerializeNodeTypes");
 
215
 
 
216
      string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
 
217
<xs:schema xs:id=""SomeID"" 
 
218
        xmlns="""" 
 
219
        xmlns:xs=""http://www.w3.org/2001/XMLSchema"" 
 
220
        xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
 
221
        <xs:element name=""MyDataSet"" msdata:IsDataSet=""true"">
 
222
        </xs:element>
 
223
</xs:schema>";
 
224
 
 
225
      XmlDocument document = new XmlDocument();
 
226
      document.LoadXml(xml);
 
227
 
 
228
      // XmlAttribute
 
229
      XmlAttribute attribute = document.DocumentElement.ChildNodes[0].Attributes["IsDataSet", "urn:schemas-microsoft-com:xml-msdata"];
 
230
      attribute.Value = "true";
 
231
 
 
232
      jsonText = JsonConvert.SerializeXmlNode(attribute);
 
233
 
 
234
      Console.WriteLine(jsonText);
 
235
      Assert.AreEqual(@"{""@msdata:IsDataSet"":""true""}", jsonText);
 
236
 
 
237
#if !NET20
 
238
      XDocument d = XDocument.Parse(xml);
 
239
      XAttribute a = d.Root.Element("{http://www.w3.org/2001/XMLSchema}element").Attribute("{urn:schemas-microsoft-com:xml-msdata}IsDataSet");
 
240
 
 
241
      jsonText = JsonConvert.SerializeXNode(a);
 
242
 
 
243
      Assert.AreEqual(@"{""@msdata:IsDataSet"":""true""}", jsonText);
 
244
#endif
 
245
 
 
246
      // XmlProcessingInstruction
 
247
      XmlProcessingInstruction instruction = doc.CreateProcessingInstruction("xml-stylesheet", @"href=""classic.xsl"" type=""text/xml""");
 
248
 
 
249
      jsonText = JsonConvert.SerializeXmlNode(instruction);
 
250
 
 
251
      Console.WriteLine(jsonText);
 
252
      Assert.AreEqual(@"{""?xml-stylesheet"":""href=\""classic.xsl\"" type=\""text/xml\""""}", jsonText);
 
253
 
 
254
 
 
255
      // XmlProcessingInstruction
 
256
      XmlCDataSection cDataSection = doc.CreateCDataSection("<Kiwi>true</Kiwi>");
 
257
 
 
258
      jsonText = JsonConvert.SerializeXmlNode(cDataSection);
 
259
 
 
260
      Console.WriteLine(jsonText);
 
261
      Assert.AreEqual(@"{""#cdata-section"":""<Kiwi>true</Kiwi>""}", jsonText);
 
262
 
 
263
 
 
264
      // XmlElement
 
265
      XmlElement element = doc.CreateElement("xs", "Choice", "http://www.w3.org/2001/XMLSchema");
 
266
      element.SetAttributeNode(doc.CreateAttribute("msdata", "IsDataSet", "urn:schemas-microsoft-com:xml-msdata"));
 
267
 
 
268
      XmlAttribute aa = doc.CreateAttribute(@"xmlns", "xs", "http://www.w3.org/2000/xmlns/");
 
269
      aa.Value = "http://www.w3.org/2001/XMLSchema";
 
270
      element.SetAttributeNode(aa);
 
271
 
 
272
      aa = doc.CreateAttribute(@"xmlns", "msdata", "http://www.w3.org/2000/xmlns/");
 
273
      aa.Value = "urn:schemas-microsoft-com:xml-msdata";
 
274
      element.SetAttributeNode(aa);
 
275
 
 
276
      element.AppendChild(instruction);
 
277
      element.AppendChild(cDataSection);
 
278
 
 
279
      doc.AppendChild(element);
 
280
 
 
281
      jsonText = JsonConvert.SerializeXmlNode(element, Formatting.Indented);
 
282
 
 
283
      Assert.AreEqual(@"{
 
284
  ""xs:Choice"": {
 
285
    ""@msdata:IsDataSet"": """",
 
286
    ""@xmlns:xs"": ""http://www.w3.org/2001/XMLSchema"",
 
287
    ""@xmlns:msdata"": ""urn:schemas-microsoft-com:xml-msdata"",
 
288
    ""?xml-stylesheet"": ""href=\""classic.xsl\"" type=\""text/xml\"""",
 
289
    ""#cdata-section"": ""<Kiwi>true</Kiwi>""
 
290
  }
 
291
}", jsonText);
 
292
    }
 
293
 
 
294
    [Test]
 
295
    public void DocumentFragmentSerialize()
 
296
    {
 
297
      XmlDocument doc = new XmlDocument();
 
298
 
 
299
      XmlDocumentFragment fragement = doc.CreateDocumentFragment();
 
300
 
 
301
      fragement.InnerXml = "<Item>widget</Item><Item>widget</Item>";
 
302
 
 
303
      string jsonText = JsonConvert.SerializeXmlNode(fragement);
 
304
 
 
305
      string expected = @"{""Item"":[""widget"",""widget""]}";
 
306
 
 
307
      Assert.AreEqual(expected, jsonText);
 
308
 
 
309
      Console.WriteLine("DocumentFragmentSerialize");
 
310
      Console.WriteLine(jsonText);
 
311
      Console.WriteLine();
 
312
    }
 
313
 
 
314
    [Test]
 
315
    public void NamespaceSerializeDeserialize()
 
316
    {
 
317
      string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
 
318
<xs:schema xs:id=""SomeID"" 
 
319
        xmlns="""" 
 
320
        xmlns:xs=""http://www.w3.org/2001/XMLSchema"" 
 
321
        xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
 
322
        <xs:element name=""MyDataSet"" msdata:IsDataSet=""true"">
 
323
                <xs:complexType>
 
324
                        <xs:choice maxOccurs=""unbounded"">
 
325
                                <xs:element name=""customers"" >
 
326
                                        <xs:complexType >
 
327
                                                <xs:sequence>
 
328
                                                        <xs:element name=""CustomerID"" type=""xs:integer"" 
 
329
                                                                                 minOccurs=""0"" />
 
330
                                                        <xs:element name=""CompanyName"" type=""xs:string"" 
 
331
                                                                                 minOccurs=""0"" />
 
332
                                                        <xs:element name=""Phone"" type=""xs:string"" />
 
333
                                                </xs:sequence>
 
334
                                        </xs:complexType>
 
335
                                </xs:element>
 
336
                        </xs:choice>
 
337
                </xs:complexType>
 
338
        </xs:element>
 
339
</xs:schema>";
 
340
 
 
341
      XmlDocument doc = new XmlDocument();
 
342
      doc.LoadXml(xml);
 
343
 
 
344
      string jsonText = SerializeXmlNode(doc);
 
345
 
 
346
      string expected = @"{
 
347
  ""?xml"": {
 
348
    ""@version"": ""1.0"",
 
349
    ""@encoding"": ""utf-8""
 
350
  },
 
351
  ""xs:schema"": {
 
352
    ""@xs:id"": ""SomeID"",
 
353
    ""@xmlns"": """",
 
354
    ""@xmlns:xs"": ""http://www.w3.org/2001/XMLSchema"",
 
355
    ""@xmlns:msdata"": ""urn:schemas-microsoft-com:xml-msdata"",
 
356
    ""xs:element"": {
 
357
      ""@name"": ""MyDataSet"",
 
358
      ""@msdata:IsDataSet"": ""true"",
 
359
      ""xs:complexType"": {
 
360
        ""xs:choice"": {
 
361
          ""@maxOccurs"": ""unbounded"",
 
362
          ""xs:element"": {
 
363
            ""@name"": ""customers"",
 
364
            ""xs:complexType"": {
 
365
              ""xs:sequence"": {
 
366
                ""xs:element"": [
 
367
                  {
 
368
                    ""@name"": ""CustomerID"",
 
369
                    ""@type"": ""xs:integer"",
 
370
                    ""@minOccurs"": ""0""
 
371
                  },
 
372
                  {
 
373
                    ""@name"": ""CompanyName"",
 
374
                    ""@type"": ""xs:string"",
 
375
                    ""@minOccurs"": ""0""
 
376
                  },
 
377
                  {
 
378
                    ""@name"": ""Phone"",
 
379
                    ""@type"": ""xs:string""
 
380
                  }
 
381
                ]
 
382
              }
 
383
            }
 
384
          }
 
385
        }
 
386
      }
 
387
    }
 
388
  }
 
389
}";
 
390
 
 
391
      Assert.AreEqual(expected, jsonText);
 
392
 
 
393
      XmlDocument deserializedDoc = (XmlDocument)DeserializeXmlNode(jsonText);
 
394
 
 
395
      Assert.AreEqual(doc.InnerXml, deserializedDoc.InnerXml);
 
396
 
 
397
      Console.WriteLine("NamespaceSerializeDeserialize");
 
398
      Console.WriteLine(jsonText);
 
399
      Console.WriteLine(deserializedDoc.InnerXml);
 
400
      Console.WriteLine();
 
401
    }
 
402
 
 
403
    [Test]
 
404
    public void DocumentDeserialize()
 
405
    {
 
406
      string jsonText = @"{
 
407
  ""?xml"": {
 
408
    ""@version"": ""1.0"",
 
409
    ""@standalone"": ""no""
 
410
  },
 
411
  ""span"": {
 
412
    ""@class"": ""vevent"",
 
413
    ""a"": {
 
414
      ""@class"": ""url"",
 
415
      ""span"": {
 
416
        ""@class"": ""summary"",
 
417
        ""#text"": ""Web 2.0 Conference"",
 
418
        ""#cdata-section"": ""my escaped text""
 
419
      },
 
420
      ""@href"": ""http://www.web2con.com/""
 
421
    }
 
422
  }
 
423
}";
 
424
 
 
425
      XmlDocument doc = (XmlDocument)DeserializeXmlNode(jsonText);
 
426
 
 
427
      string expected = @"<?xml version=""1.0"" standalone=""no""?>
 
428
<span class=""vevent"">
 
429
  <a class=""url"" href=""http://www.web2con.com/"">
 
430
    <span class=""summary"">Web 2.0 Conference<![CDATA[my escaped text]]></span>
 
431
  </a>
 
432
</span>";
 
433
 
 
434
      string formattedXml = GetIndentedInnerXml(doc);
 
435
 
 
436
      Console.WriteLine("DocumentDeserialize");
 
437
      Console.WriteLine(formattedXml);
 
438
      Console.WriteLine();
 
439
 
 
440
      Assert.AreEqual(expected, formattedXml);
 
441
    }
 
442
 
 
443
    private string GetIndentedInnerXml(XmlNode node)
 
444
    {
 
445
      XmlWriterSettings settings = new XmlWriterSettings();
 
446
      settings.Indent = true;
 
447
 
 
448
      StringWriter sw = new StringWriter();
 
449
 
 
450
      using (XmlWriter writer = XmlWriter.Create(sw, settings))
 
451
      {
 
452
        node.WriteTo(writer);
 
453
      }
 
454
 
 
455
      return sw.ToString();
 
456
    }
 
457
 
 
458
    [Test]
 
459
    public void SingleTextNode()
 
460
    {
 
461
      string xml = @"<?xml version=""1.0"" standalone=""no""?>
 
462
                        <root>
 
463
                          <person id=""1"">
 
464
                                <name>Alan</name>
 
465
                                <url>http://www.google.com</url>
 
466
                          </person>
 
467
                          <person id=""2"">
 
468
                                <name>Louis</name>
 
469
                                  <url>http://www.yahoo.com</url>
 
470
                          </person>
 
471
                        </root>";
 
472
 
 
473
      XmlDocument doc = new XmlDocument();
 
474
      doc.LoadXml(xml);
 
475
 
 
476
      string jsonText = SerializeXmlNode(doc);
 
477
 
 
478
      XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
 
479
 
 
480
      Assert.AreEqual(doc.InnerXml, newDoc.InnerXml);
 
481
    }
 
482
 
 
483
    [Test]
 
484
    public void EmptyNode()
 
485
    {
 
486
      string xml = @"<?xml version=""1.0"" standalone=""no""?>
 
487
                        <root>
 
488
                          <person id=""1"">
 
489
                                <name>Alan</name>
 
490
                                <url />
 
491
                          </person>
 
492
                          <person id=""2"">
 
493
                                <name>Louis</name>
 
494
                                <url>http://www.yahoo.com</url>
 
495
                          </person>
 
496
                        </root>";
 
497
 
 
498
      XmlDocument doc = new XmlDocument();
 
499
      doc.LoadXml(xml);
 
500
 
 
501
      string jsonText = SerializeXmlNode(doc);
 
502
 
 
503
      Console.WriteLine(jsonText);
 
504
 
 
505
      XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
 
506
 
 
507
      Assert.AreEqual(doc.InnerXml, newDoc.InnerXml);
 
508
    }
 
509
 
 
510
    [Test]
 
511
    public void OtherElementDataTypes()
 
512
    {
 
513
      string jsonText = @"{""?xml"":{""@version"":""1.0"",""@standalone"":""no""},""root"":{""person"":[{""@id"":""1"",""Float"":2.5,""Integer"":99},{""Boolean"":true,""@id"":""2"",""date"":""\/Date(954374400000)\/""}]}}";
 
514
 
 
515
      XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
 
516
 
 
517
      string expected = @"<?xml version=""1.0"" standalone=""no""?><root><person id=""1""><Float>2.5</Float><Integer>99</Integer></person><person id=""2""><Boolean>true</Boolean><date>2000-03-30T00:00:00Z</date></person></root>";
 
518
 
 
519
      Assert.AreEqual(expected, newDoc.InnerXml);
 
520
    }
 
521
 
 
522
    [Test]
 
523
    public void NoRootObject()
 
524
    {
 
525
      ExceptionAssert.Throws<JsonSerializationException>(
 
526
        "XmlNodeConverter can only convert JSON that begins with an object.",
 
527
        () =>
 
528
          {
 
529
            XmlDocument newDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"[1]");
 
530
          });
 
531
    }
 
532
 
 
533
    [Test]
 
534
    public void RootObjectMultipleProperties()
 
535
    {
 
536
      ExceptionAssert.Throws<JsonSerializationException>(
 
537
        "JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.",
 
538
        () =>
 
539
        {
 
540
          XmlDocument newDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"{Prop1:1,Prop2:2}");
 
541
        });
 
542
    }
 
543
 
 
544
    [Test]
 
545
    public void JavaScriptConstructor()
 
546
    {
 
547
      string jsonText = @"{root:{r:new Date(34343, 55)}}";
 
548
 
 
549
      XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
 
550
 
 
551
      string expected = @"<root><r><Date>34343</Date><Date>55</Date></r></root>";
 
552
 
 
553
      Assert.AreEqual(expected, newDoc.InnerXml);
 
554
 
 
555
      string json = SerializeXmlNode(newDoc);
 
556
      expected = @"{
 
557
  ""root"": {
 
558
    ""r"": {
 
559
      ""Date"": [
 
560
        ""34343"",
 
561
        ""55""
 
562
      ]
 
563
    }
 
564
  }
 
565
}";
 
566
 
 
567
      Assert.AreEqual(expected, json);
 
568
    }
 
569
 
 
570
    [Test]
 
571
    public void ForceJsonArray()
 
572
    {
 
573
      string arrayXml = @"<root xmlns:json=""http://james.newtonking.com/projects/json"">
 
574
                          <person id=""1"">
 
575
                                  <name>Alan</name>
 
576
                                  <url>http://www.google.com</url>
 
577
                                  <role json:Array=""true"">Admin</role>
 
578
                          </person>
 
579
                        </root>";
 
580
 
 
581
      XmlDocument arrayDoc = new XmlDocument();
 
582
      arrayDoc.LoadXml(arrayXml);
 
583
 
 
584
      string arrayJsonText = SerializeXmlNode(arrayDoc);
 
585
      string expected = @"{
 
586
  ""root"": {
 
587
    ""person"": {
 
588
      ""@id"": ""1"",
 
589
      ""name"": ""Alan"",
 
590
      ""url"": ""http://www.google.com"",
 
591
      ""role"": [
 
592
        ""Admin""
 
593
      ]
 
594
    }
 
595
  }
 
596
}";
 
597
      Assert.AreEqual(expected, arrayJsonText);
 
598
 
 
599
      arrayXml = @"<root xmlns:json=""http://james.newtonking.com/projects/json"">
 
600
                          <person id=""1"">
 
601
                                  <name>Alan</name>
 
602
                                  <url>http://www.google.com</url>
 
603
                                  <role json:Array=""true"">Admin1</role>
 
604
                                  <role json:Array=""true"">Admin2</role>
 
605
                          </person>
 
606
                        </root>";
 
607
 
 
608
      arrayDoc = new XmlDocument();
 
609
      arrayDoc.LoadXml(arrayXml);
 
610
 
 
611
      arrayJsonText = SerializeXmlNode(arrayDoc);
 
612
      expected = @"{
 
613
  ""root"": {
 
614
    ""person"": {
 
615
      ""@id"": ""1"",
 
616
      ""name"": ""Alan"",
 
617
      ""url"": ""http://www.google.com"",
 
618
      ""role"": [
 
619
        ""Admin1"",
 
620
        ""Admin2""
 
621
      ]
 
622
    }
 
623
  }
 
624
}";
 
625
      Assert.AreEqual(expected, arrayJsonText);
 
626
 
 
627
      arrayXml = @"<root xmlns:json=""http://james.newtonking.com/projects/json"">
 
628
                          <person id=""1"">
 
629
                                  <name>Alan</name>
 
630
                                  <url>http://www.google.com</url>
 
631
                                  <role json:Array=""false"">Admin1</role>
 
632
                          </person>
 
633
                        </root>";
 
634
 
 
635
      arrayDoc = new XmlDocument();
 
636
      arrayDoc.LoadXml(arrayXml);
 
637
 
 
638
      arrayJsonText = SerializeXmlNode(arrayDoc);
 
639
      expected = @"{
 
640
  ""root"": {
 
641
    ""person"": {
 
642
      ""@id"": ""1"",
 
643
      ""name"": ""Alan"",
 
644
      ""url"": ""http://www.google.com"",
 
645
      ""role"": ""Admin1""
 
646
    }
 
647
  }
 
648
}";
 
649
      Assert.AreEqual(expected, arrayJsonText);
 
650
    }
 
651
 
 
652
    [Test]
 
653
    public void MultipleRootPropertiesXmlDocument()
 
654
    {
 
655
      string json = @"{""count"": 773840,""photos"": null}";
 
656
 
 
657
      ExceptionAssert.Throws<JsonSerializationException>(
 
658
        "JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.",
 
659
        () =>
 
660
        {
 
661
          JsonConvert.DeserializeXmlNode(json);
 
662
        });
 
663
    }
 
664
 
 
665
#if !NET20
 
666
    [Test]
 
667
    public void MultipleRootPropertiesXDocument()
 
668
    {
 
669
      string json = @"{""count"": 773840,""photos"": null}";
 
670
 
 
671
      ExceptionAssert.Throws<JsonSerializationException>(
 
672
        "JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.",
 
673
        () =>
 
674
        {
 
675
          JsonConvert.DeserializeXNode(json);
 
676
        });
 
677
    }
 
678
#endif
 
679
 
 
680
    [Test]
 
681
    public void MultipleRootPropertiesAddRootElement()
 
682
    {
 
683
      string json = @"{""count"": 773840,""photos"": 773840}";
 
684
 
 
685
      XmlDocument newDoc = JsonConvert.DeserializeXmlNode(json, "myRoot");
 
686
 
 
687
      Assert.AreEqual(@"<myRoot><count>773840</count><photos>773840</photos></myRoot>", newDoc.InnerXml);
 
688
 
 
689
#if !NET20
 
690
     XDocument newXDoc = JsonConvert.DeserializeXNode(json, "myRoot");
 
691
 
 
692
      Assert.AreEqual(@"<myRoot><count>773840</count><photos>773840</photos></myRoot>", newXDoc.ToString(SaveOptions.DisableFormatting));
 
693
#endif
 
694
    }
 
695
 
 
696
    [Test]
 
697
    public void NestedArrays()
 
698
    {
 
699
      string json = @"{
 
700
  ""available_sizes"": [
 
701
    [
 
702
      ""assets/images/resized/0001/1070/11070v1-max-150x150.jpg"",
 
703
      ""assets/images/resized/0001/1070/11070v1-max-150x150.jpg""
 
704
    ],
 
705
    [
 
706
      ""assets/images/resized/0001/1070/11070v1-max-250x250.jpg"",
 
707
      ""assets/images/resized/0001/1070/11070v1-max-250x250.jpg""
 
708
    ],
 
709
    [
 
710
      ""assets/images/resized/0001/1070/11070v1-max-250x250.jpg""
 
711
    ]
 
712
  ]
 
713
}";
 
714
 
 
715
      XmlDocument newDoc = JsonConvert.DeserializeXmlNode(json, "myRoot");
 
716
 
 
717
      string xml = IndentXml(newDoc.InnerXml);
 
718
 
 
719
      Assert.AreEqual(@"<myRoot>
 
720
  <available_sizes>
 
721
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes>
 
722
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes>
 
723
  </available_sizes>
 
724
  <available_sizes>
 
725
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
726
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
727
  </available_sizes>
 
728
  <available_sizes>
 
729
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
730
  </available_sizes>
 
731
</myRoot>", IndentXml(newDoc.InnerXml));
 
732
 
 
733
#if !NET20
 
734
      XDocument newXDoc = JsonConvert.DeserializeXNode(json, "myRoot");
 
735
 
 
736
      Assert.AreEqual(@"<myRoot>
 
737
  <available_sizes>
 
738
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes>
 
739
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes>
 
740
  </available_sizes>
 
741
  <available_sizes>
 
742
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
743
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
744
  </available_sizes>
 
745
  <available_sizes>
 
746
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
747
  </available_sizes>
 
748
</myRoot>", IndentXml(newXDoc.ToString(SaveOptions.DisableFormatting)));
 
749
#endif
 
750
 
 
751
      string newJson = JsonConvert.SerializeXmlNode(newDoc, Formatting.Indented);
 
752
      Console.WriteLine(newJson);
 
753
    }
 
754
 
 
755
    [Test]
 
756
    public void RoundTripNestedArrays()
 
757
    {
 
758
      string json = @"{
 
759
  ""available_sizes"": [
 
760
    [
 
761
      ""assets/images/resized/0001/1070/11070v1-max-150x150.jpg"",
 
762
      ""assets/images/resized/0001/1070/11070v1-max-150x150.jpg""
 
763
    ],
 
764
    [
 
765
      ""assets/images/resized/0001/1070/11070v1-max-250x250.jpg"",
 
766
      ""assets/images/resized/0001/1070/11070v1-max-250x250.jpg""
 
767
    ],
 
768
    [
 
769
      ""assets/images/resized/0001/1070/11070v1-max-250x250.jpg""
 
770
    ]
 
771
  ]
 
772
}";
 
773
 
 
774
      XmlDocument newDoc = JsonConvert.DeserializeXmlNode(json, "myRoot", true);
 
775
 
 
776
      Assert.AreEqual(@"<myRoot>
 
777
  <available_sizes json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">
 
778
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes>
 
779
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes>
 
780
  </available_sizes>
 
781
  <available_sizes json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">
 
782
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
783
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
784
  </available_sizes>
 
785
  <available_sizes json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">
 
786
    <available_sizes json:Array=""true"">assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
787
  </available_sizes>
 
788
</myRoot>", IndentXml(newDoc.InnerXml));
 
789
 
 
790
#if !NET20
 
791
      XDocument newXDoc = JsonConvert.DeserializeXNode(json, "myRoot", true);
 
792
 
 
793
      Console.WriteLine(IndentXml(newXDoc.ToString(SaveOptions.DisableFormatting)));
 
794
 
 
795
      Assert.AreEqual(@"<myRoot>
 
796
  <available_sizes json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">
 
797
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes>
 
798
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes>
 
799
  </available_sizes>
 
800
  <available_sizes json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">
 
801
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
802
    <available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
803
  </available_sizes>
 
804
  <available_sizes json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">
 
805
    <available_sizes json:Array=""true"">assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
 
806
  </available_sizes>
 
807
</myRoot>", IndentXml(newXDoc.ToString(SaveOptions.DisableFormatting)));
 
808
#endif
 
809
 
 
810
      string newJson = JsonConvert.SerializeXmlNode(newDoc, Formatting.Indented, true);
 
811
      Assert.AreEqual(json, newJson);
 
812
    }
 
813
 
 
814
    [Test]
 
815
    public void MultipleNestedArraysToXml()
 
816
    {
 
817
      string json = @"{
 
818
  ""available_sizes"": [
 
819
    [
 
820
      [113, 150],
 
821
      ""assets/images/resized/0001/1070/11070v1-max-150x150.jpg""
 
822
    ],
 
823
    [
 
824
      [189, 250],
 
825
      ""assets/images/resized/0001/1070/11070v1-max-250x250.jpg""
 
826
    ],
 
827
    [
 
828
      [341, 450],
 
829
      ""assets/images/resized/0001/1070/11070v1-max-450x450.jpg""
 
830
    ]
 
831
  ]
 
832
}";
 
833
 
 
834
      XmlDocument newDoc = JsonConvert.DeserializeXmlNode(json, "myRoot");
 
835
 
 
836
      Assert.AreEqual(@"<myRoot><available_sizes><available_sizes><available_sizes>113</available_sizes><available_sizes>150</available_sizes></available_sizes><available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes></available_sizes><available_sizes><available_sizes><available_sizes>189</available_sizes><available_sizes>250</available_sizes></available_sizes><available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes></available_sizes><available_sizes><available_sizes><available_sizes>341</available_sizes><available_sizes>450</available_sizes></available_sizes><available_sizes>assets/images/resized/0001/1070/11070v1-max-450x450.jpg</available_sizes></available_sizes></myRoot>", newDoc.InnerXml);
 
837
 
 
838
#if !NET20
 
839
      XDocument newXDoc = JsonConvert.DeserializeXNode(json, "myRoot");
 
840
 
 
841
      Assert.AreEqual(@"<myRoot><available_sizes><available_sizes><available_sizes>113</available_sizes><available_sizes>150</available_sizes></available_sizes><available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes></available_sizes><available_sizes><available_sizes><available_sizes>189</available_sizes><available_sizes>250</available_sizes></available_sizes><available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes></available_sizes><available_sizes><available_sizes><available_sizes>341</available_sizes><available_sizes>450</available_sizes></available_sizes><available_sizes>assets/images/resized/0001/1070/11070v1-max-450x450.jpg</available_sizes></available_sizes></myRoot>", newXDoc.ToString(SaveOptions.DisableFormatting));
 
842
#endif
 
843
    }
 
844
 
 
845
    [Test]
 
846
    public void Encoding()
 
847
    {
 
848
      XmlDocument doc = new XmlDocument();
 
849
 
 
850
      doc.LoadXml(@"<name>O""Connor</name>"); // i use "" so it will be easier to see the  problem
 
851
 
 
852
      string json = SerializeXmlNode(doc);
 
853
      Assert.AreEqual(@"{
 
854
  ""name"": ""O\""Connor""
 
855
}", json);
 
856
    }
 
857
 
 
858
    [Test]
 
859
    public void SerializeComment()
 
860
    {
 
861
      string xml = @"<span class=""vevent"">
 
862
  <a class=""url"" href=""http://www.web2con.com/"">Text</a><!-- Hi! -->
 
863
</span>";
 
864
      XmlDocument doc = new XmlDocument();
 
865
      doc.LoadXml(xml);
 
866
 
 
867
      string jsonText = SerializeXmlNode(doc);
 
868
 
 
869
      string expected = @"{
 
870
  ""span"": {
 
871
    ""@class"": ""vevent"",
 
872
    ""a"": {
 
873
      ""@class"": ""url"",
 
874
      ""@href"": ""http://www.web2con.com/"",
 
875
      ""#text"": ""Text""
 
876
    }/* Hi! */
 
877
  }
 
878
}";
 
879
 
 
880
      Assert.AreEqual(expected, jsonText);
 
881
 
 
882
      XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
 
883
      Assert.AreEqual(@"<span class=""vevent""><a class=""url"" href=""http://www.web2con.com/"">Text</a><!-- Hi! --></span>", newDoc.InnerXml);
 
884
    }
 
885
 
 
886
    [Test]
 
887
    public void SerializeExample()
 
888
    {
 
889
      string xml = @"<?xml version=""1.0"" standalone=""no""?>
 
890
                        <root>
 
891
                          <person id=""1"">
 
892
                                <name>Alan</name>
 
893
                                <url>http://www.google.com</url>
 
894
                          </person>
 
895
                          <person id=""2"">
 
896
                                <name>Louis</name>
 
897
                                <url>http://www.yahoo.com</url>
 
898
                          </person>
 
899
                        </root>";
 
900
 
 
901
      XmlDocument doc = new XmlDocument();
 
902
      doc.LoadXml(xml);
 
903
 
 
904
      string jsonText = SerializeXmlNode(doc);
 
905
      // {
 
906
      //   "?xml": {
 
907
      //     "@version": "1.0",
 
908
      //     "@standalone": "no"
 
909
      //   },
 
910
      //   "root": {
 
911
      //     "person": [
 
912
      //       {
 
913
      //         "@id": "1",
 
914
      //         "name": "Alan",
 
915
      //         "url": "http://www.google.com"
 
916
      //       },
 
917
      //       {
 
918
      //         "@id": "2",
 
919
      //         "name": "Louis",
 
920
      //         "url": "http://www.yahoo.com"
 
921
      //       }
 
922
      //     ]
 
923
      //   }
 
924
      // }
 
925
 
 
926
      // format
 
927
      jsonText = JObject.Parse(jsonText).ToString();
 
928
 
 
929
      Assert.AreEqual(@"{
 
930
  ""?xml"": {
 
931
    ""@version"": ""1.0"",
 
932
    ""@standalone"": ""no""
 
933
  },
 
934
  ""root"": {
 
935
    ""person"": [
 
936
      {
 
937
        ""@id"": ""1"",
 
938
        ""name"": ""Alan"",
 
939
        ""url"": ""http://www.google.com""
 
940
      },
 
941
      {
 
942
        ""@id"": ""2"",
 
943
        ""name"": ""Louis"",
 
944
        ""url"": ""http://www.yahoo.com""
 
945
      }
 
946
    ]
 
947
  }
 
948
}", jsonText);
 
949
 
 
950
      XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
 
951
 
 
952
      Assert.AreEqual(doc.InnerXml, newDoc.InnerXml);
 
953
    }
 
954
 
 
955
    [Test]
 
956
    public void DeserializeExample()
 
957
    {
 
958
      string json = @"{
 
959
        ""?xml"": {
 
960
          ""@version"": ""1.0"",
 
961
          ""@standalone"": ""no""
 
962
        },
 
963
        ""root"": {
 
964
          ""person"": [
 
965
            {
 
966
              ""@id"": ""1"",
 
967
              ""name"": ""Alan"",
 
968
              ""url"": ""http://www.google.com""
 
969
            },
 
970
            {
 
971
              ""@id"": ""2"",
 
972
              ""name"": ""Louis"",
 
973
              ""url"": ""http://www.yahoo.com""
 
974
            }
 
975
          ]
 
976
        }
 
977
      }";
 
978
 
 
979
      XmlDocument doc = (XmlDocument)DeserializeXmlNode(json);
 
980
      // <?xml version="1.0" standalone="no"?>
 
981
      // <root>
 
982
      //   <person id="1">
 
983
      //   <name>Alan</name>
 
984
      //   <url>http://www.google.com</url>
 
985
      //   </person>
 
986
      //   <person id="2">
 
987
      //   <name>Louis</name>
 
988
      //   <url>http://www.yahoo.com</url>
 
989
      //   </person>
 
990
      // </root>
 
991
 
 
992
      Assert.AreEqual(@"<?xml version=""1.0"" standalone=""no""?>
 
993
<root>
 
994
<person id=""1"">
 
995
<name>Alan</name>
 
996
<url>http://www.google.com</url>
 
997
</person>
 
998
<person id=""2"">
 
999
<name>Louis</name>
 
1000
<url>http://www.yahoo.com</url>
 
1001
</person>
 
1002
</root>".Replace(Environment.NewLine, string.Empty), doc.InnerXml);
 
1003
    }
 
1004
 
 
1005
    [Test]
 
1006
    public void SerializeDeserializeSpecialProperties()
 
1007
    {
 
1008
      PreserveReferencesHandlingTests.CircularDictionary circularDictionary = new PreserveReferencesHandlingTests.CircularDictionary();
 
1009
      circularDictionary.Add("other", new PreserveReferencesHandlingTests.CircularDictionary { { "blah", null } });
 
1010
      circularDictionary.Add("self", circularDictionary);
 
1011
 
 
1012
      string json = JsonConvert.SerializeObject(circularDictionary, Formatting.Indented,
 
1013
        new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.All });
 
1014
 
 
1015
      Assert.AreEqual(@"{
 
1016
  ""$id"": ""1"",
 
1017
  ""other"": {
 
1018
    ""$id"": ""2"",
 
1019
    ""blah"": null
 
1020
  },
 
1021
  ""self"": {
 
1022
    ""$ref"": ""1""
 
1023
  }
 
1024
}", json);
 
1025
 
 
1026
      XmlNode node = DeserializeXmlNode(json, "root");
 
1027
      string xml = GetIndentedInnerXml(node);
 
1028
      string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
 
1029
<root xmlns:json=""http://james.newtonking.com/projects/json"" json:id=""1"">
 
1030
  <other json:id=""2"">
 
1031
    <blah />
 
1032
  </other>
 
1033
  <self json:ref=""1"" />
 
1034
</root>";
 
1035
 
 
1036
      Assert.AreEqual(expected, xml);
 
1037
 
 
1038
      string xmlJson = SerializeXmlNode(node);
 
1039
      string expectedXmlJson = @"{
 
1040
  ""root"": {
 
1041
    ""$id"": ""1"",
 
1042
    ""other"": {
 
1043
      ""$id"": ""2"",
 
1044
      ""blah"": null
 
1045
    },
 
1046
    ""self"": {
 
1047
      ""$ref"": ""1""
 
1048
    }
 
1049
  }
 
1050
}";
 
1051
 
 
1052
      Assert.AreEqual(expectedXmlJson, xmlJson);
 
1053
    }
 
1054
 
 
1055
    [Test]
 
1056
    public void EmptyPropertyName()
 
1057
    {
 
1058
      string json = @"{
 
1059
  ""8452309520V2"": {
 
1060
    """": {
 
1061
      ""CLIENT"": {
 
1062
        ""ID_EXPIRATION_1"": {
 
1063
          ""VALUE"": ""12/12/2000"",
 
1064
          ""DATATYPE"": ""D"",
 
1065
          ""MSG"": ""Missing Identification Exp. Date 1""
 
1066
        },
 
1067
        ""ID_ISSUEDATE_1"": {
 
1068
          ""VALUE"": """",
 
1069
          ""DATATYPE"": ""D"",
 
1070
          ""MSG"": ""Missing Identification Issue Date 1""
 
1071
        }
 
1072
      }
 
1073
    },
 
1074
    ""457463534534"": {
 
1075
      ""ACCOUNT"": {
 
1076
        ""FUNDING_SOURCE"": {
 
1077
          ""VALUE"": ""FS0"",
 
1078
          ""DATATYPE"": ""L"",
 
1079
          ""MSG"": ""Missing Source of Funds""
 
1080
        }
 
1081
      }
 
1082
    }
 
1083
  }
 
1084
}{
 
1085
  ""34534634535345"": {
 
1086
    """": {
 
1087
      ""CLIENT"": {
 
1088
        ""ID_NUMBER_1"": {
 
1089
          ""VALUE"": """",
 
1090
          ""DATATYPE"": ""S"",
 
1091
          ""MSG"": ""Missing Picture ID""
 
1092
        },
 
1093
        ""ID_EXPIRATION_1"": {
 
1094
          ""VALUE"": ""12/12/2000"",
 
1095
          ""DATATYPE"": ""D"",
 
1096
          ""MSG"": ""Missing Picture ID""
 
1097
        },
 
1098
        ""WALK_IN"": {
 
1099
          ""VALUE"": """",
 
1100
          ""DATATYPE"": ""L"",
 
1101
          ""MSG"": ""Missing Walk in""
 
1102
        },
 
1103
        ""PERSONAL_MEETING"": {
 
1104
          ""VALUE"": ""PM1"",
 
1105
          ""DATATYPE"": ""L"",
 
1106
          ""MSG"": ""Missing Met Client in Person""
 
1107
        },
 
1108
        ""ID_ISSUEDATE_1"": {
 
1109
          ""VALUE"": """",
 
1110
          ""DATATYPE"": ""D"",
 
1111
          ""MSG"": ""Missing Picture ID""
 
1112
        },
 
1113
        ""PHOTO_ID"": {
 
1114
          ""VALUE"": """",
 
1115
          ""DATATYPE"": ""L"",
 
1116
          ""MSG"": ""Missing Picture ID""
 
1117
        },
 
1118
        ""ID_TYPE_1"": {
 
1119
          ""VALUE"": """",
 
1120
          ""DATATYPE"": ""L"",
 
1121
          ""MSG"": ""Missing Picture ID""
 
1122
        }
 
1123
      }
 
1124
    },
 
1125
    ""45635624523"": {
 
1126
      ""ACCOUNT"": {
 
1127
        ""FUNDING_SOURCE"": {
 
1128
          ""VALUE"": ""FS1"",
 
1129
          ""DATATYPE"": ""L"",
 
1130
          ""MSG"": ""Missing Source of Funds""
 
1131
        }
 
1132
      }
 
1133
    }
 
1134
  }
 
1135
}";
 
1136
 
 
1137
      ExceptionAssert.Throws<JsonSerializationException>(
 
1138
        "XmlNodeConverter cannot convert JSON with an empty property name to XML.",
 
1139
        () =>
 
1140
        {
 
1141
          DeserializeXmlNode(json);
 
1142
        });
 
1143
    }
 
1144
 
 
1145
    [Test]
 
1146
    public void SingleItemArrayPropertySerialization()
 
1147
    {
 
1148
      Product product = new Product();
 
1149
 
 
1150
      product.Name = "Apple";
 
1151
      product.ExpiryDate = new DateTime(2008, 12, 28, 0, 0, 0, DateTimeKind.Utc);
 
1152
      product.Price = 3.99M;
 
1153
      product.Sizes = new string[] { "Small" };
 
1154
 
 
1155
      string output = JsonConvert.SerializeObject(product, new IsoDateTimeConverter());
 
1156
 
 
1157
      XmlDocument xmlProduct = JsonConvert.DeserializeXmlNode(output, "product", true);
 
1158
 
 
1159
      Assert.AreEqual(@"<product>
 
1160
  <Name>Apple</Name>
 
1161
  <ExpiryDate>2008-12-28T00:00:00Z</ExpiryDate>
 
1162
  <Price>3.99</Price>
 
1163
  <Sizes json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">Small</Sizes>
 
1164
</product>", IndentXml(xmlProduct.InnerXml));
 
1165
 
 
1166
      string output2 = JsonConvert.SerializeXmlNode(xmlProduct.DocumentElement, Formatting.Indented);
 
1167
 
 
1168
      Assert.AreEqual(@"{
 
1169
  ""product"": {
 
1170
    ""Name"": ""Apple"",
 
1171
    ""ExpiryDate"": ""2008-12-28T00:00:00Z"",
 
1172
    ""Price"": ""3.99"",
 
1173
    ""Sizes"": [
 
1174
      ""Small""
 
1175
    ]
 
1176
  }
 
1177
}", output2);
 
1178
    }
 
1179
 
 
1180
    public class TestComplexArrayClass
 
1181
    {
 
1182
      public string Name { get; set; }
 
1183
      public IList<Product> Products { get; set; }
 
1184
    }
 
1185
 
 
1186
    [Test]
 
1187
    public void ComplexSingleItemArrayPropertySerialization()
 
1188
    {
 
1189
      TestComplexArrayClass o = new TestComplexArrayClass
 
1190
        {
 
1191
          Name = "Hi",
 
1192
          Products = new List<Product>
 
1193
            {
 
1194
              new Product { Name = "First" }
 
1195
            }
 
1196
        };
 
1197
 
 
1198
      string output = JsonConvert.SerializeObject(o, new IsoDateTimeConverter());
 
1199
 
 
1200
      XmlDocument xmlProduct = JsonConvert.DeserializeXmlNode(output, "test", true);
 
1201
 
 
1202
      Assert.AreEqual(@"<test>
 
1203
  <Name>Hi</Name>
 
1204
  <Products json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">
 
1205
    <Name>First</Name>
 
1206
    <ExpiryDate>2000-01-01T00:00:00Z</ExpiryDate>
 
1207
    <Price>0</Price>
 
1208
    <Sizes />
 
1209
  </Products>
 
1210
</test>", IndentXml(xmlProduct.InnerXml));
 
1211
 
 
1212
      string output2 = JsonConvert.SerializeXmlNode(xmlProduct.DocumentElement, Formatting.Indented, true);
 
1213
 
 
1214
      Assert.AreEqual(@"{
 
1215
  ""Name"": ""Hi"",
 
1216
  ""Products"": [
 
1217
    {
 
1218
      ""Name"": ""First"",
 
1219
      ""ExpiryDate"": ""2000-01-01T00:00:00Z"",
 
1220
      ""Price"": ""0"",
 
1221
      ""Sizes"": null
 
1222
    }
 
1223
  ]
 
1224
}", output2);
 
1225
    }
 
1226
 
 
1227
    private string IndentXml(string xml)
 
1228
    {
 
1229
      XmlReader reader = XmlReader.Create(new StringReader(xml));
 
1230
 
 
1231
      StringWriter sw = new StringWriter();
 
1232
      XmlWriter writer = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true });
 
1233
 
 
1234
      while (reader.Read())
 
1235
      {
 
1236
        writer.WriteNode(reader, false);
 
1237
      }
 
1238
 
 
1239
      writer.Flush();
 
1240
 
 
1241
      return sw.ToString();
 
1242
    }
 
1243
 
 
1244
    [Test]
 
1245
    public void OmitRootObject()
 
1246
    {
 
1247
      string xml = @"<test>
 
1248
  <Name>Hi</Name>
 
1249
  <Name>Hi</Name>
 
1250
  <Products json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">
 
1251
    <Name>First</Name>
 
1252
    <ExpiryDate>2000-01-01T00:00:00Z</ExpiryDate>
 
1253
    <Price>0</Price>
 
1254
    <Sizes />
 
1255
  </Products>
 
1256
</test>";
 
1257
 
 
1258
      XmlDocument d = new XmlDocument();
 
1259
      d.LoadXml(xml);
 
1260
 
 
1261
      string output = JsonConvert.SerializeXmlNode(d, Formatting.Indented, true);
 
1262
 
 
1263
      Assert.AreEqual(@"{
 
1264
  ""Name"": [
 
1265
    ""Hi"",
 
1266
    ""Hi""
 
1267
  ],
 
1268
  ""Products"": [
 
1269
    {
 
1270
      ""Name"": ""First"",
 
1271
      ""ExpiryDate"": ""2000-01-01T00:00:00Z"",
 
1272
      ""Price"": ""0"",
 
1273
      ""Sizes"": null
 
1274
    }
 
1275
  ]
 
1276
}", output);
 
1277
    }
 
1278
 
 
1279
    [Test]
 
1280
    public void EmtpyElementWithArrayAttributeShouldWriteAttributes()
 
1281
    {
 
1282
      string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
 
1283
<root xmlns:json=""http://james.newtonking.com/projects/json"">
 
1284
<A>
 
1285
<B name=""sample"" json:Array=""true""/>
 
1286
<C></C>
 
1287
<C></C>
 
1288
</A>
 
1289
</root>";
 
1290
 
 
1291
      XmlDocument d = new XmlDocument();
 
1292
      d.LoadXml(xml);
 
1293
 
 
1294
      string json = JsonConvert.SerializeXmlNode(d, Formatting.Indented);
 
1295
 
 
1296
      Assert.AreEqual(@"{
 
1297
  ""?xml"": {
 
1298
    ""@version"": ""1.0"",
 
1299
    ""@encoding"": ""utf-8""
 
1300
  },
 
1301
  ""root"": {
 
1302
    ""A"": {
 
1303
      ""B"": [
 
1304
        {
 
1305
          ""@name"": ""sample""
 
1306
        }
 
1307
      ],
 
1308
      ""C"": [
 
1309
        null,
 
1310
        null
 
1311
      ]
 
1312
    }
 
1313
  }
 
1314
}", json);
 
1315
    }
 
1316
 
 
1317
    [Test]
 
1318
    public void EmtpyElementWithArrayAttributeShouldWriteElement()
 
1319
    {
 
1320
      string xml = @"<root>
 
1321
<Reports d1p1:Array=""true"" xmlns:d1p1=""http://james.newtonking.com/projects/json"" />
 
1322
</root>";
 
1323
 
 
1324
      XmlDocument d = new XmlDocument();
 
1325
      d.LoadXml(xml);
 
1326
 
 
1327
      string json = JsonConvert.SerializeXmlNode(d, Formatting.Indented);
 
1328
 
 
1329
      Assert.AreEqual(@"{
 
1330
  ""root"": {
 
1331
    ""Reports"": [
 
1332
      {}
 
1333
    ]
 
1334
  }
 
1335
}", json);
 
1336
    }
 
1337
 
 
1338
    [Test]
 
1339
    public void DeserializeNonInt64IntegerValues()
 
1340
    {
 
1341
      var dict = new Dictionary<string, object> { { "Int16", (short)1 }, { "Float", 2f }, { "Int32", 3 } };
 
1342
      var obj = JObject.FromObject(dict);
 
1343
      var serializer = JsonSerializer.Create(new JsonSerializerSettings { Converters = { new XmlNodeConverter() { DeserializeRootElementName = "root" } } });
 
1344
      using (var reader = obj.CreateReader())
 
1345
      {
 
1346
        var value = (XmlDocument)serializer.Deserialize(reader, typeof(XmlDocument));
 
1347
 
 
1348
        Assert.AreEqual(@"<root><Int16>1</Int16><Float>2</Float><Int32>3</Int32></root>", value.InnerXml);
 
1349
      }
 
1350
    }
 
1351
 
 
1352
    [Test]
 
1353
    public void DeserializingBooleanValues()
 
1354
    {
 
1355
      MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(@"{root:{""@booleanType"":true}}"));
 
1356
      MemoryStream xml = new MemoryStream();
 
1357
 
 
1358
      JsonBodyToSoapXml(ms, xml);
 
1359
 
 
1360
      string xmlString = System.Text.Encoding.UTF8.GetString(xml.ToArray());
 
1361
 
 
1362
      Assert.AreEqual(@"ļ»æ<?xml version=""1.0"" encoding=""utf-8""?><root booleanType=""true"" />", xmlString);
 
1363
    }
 
1364
 
 
1365
    private static void JsonBodyToSoapXml(Stream json, Stream xml)
 
1366
    {
 
1367
      Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
 
1368
      settings.Converters.Add(new Newtonsoft.Json.Converters.XmlNodeConverter());
 
1369
      Newtonsoft.Json.JsonSerializer serializer = Newtonsoft.Json.JsonSerializer.Create(settings);
 
1370
      using (Newtonsoft.Json.JsonTextReader reader = new Newtonsoft.Json.JsonTextReader(new System.IO.StreamReader(json)))
 
1371
      {
 
1372
        XmlDocument doc = (XmlDocument)serializer.Deserialize(reader, typeof(XmlDocument));
 
1373
        if (reader.Read() && reader.TokenType != JsonToken.Comment)
 
1374
          throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object.");
 
1375
        using (XmlWriter writer = XmlWriter.Create(xml))
 
1376
        {
 
1377
          doc.Save(writer);
 
1378
        }
 
1379
      }
 
1380
    }
 
1381
 
 
1382
#if !NET20
 
1383
    [Test]
 
1384
    public void DeserializeXNodeDefaultNamespace()
 
1385
    {
 
1386
      string xaml = @"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:toolkit=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"" Style=""{StaticResource trimFormGrid}"" x:Name=""TrimObjectForm"">
 
1387
  <Grid.ColumnDefinitions>
 
1388
    <ColumnDefinition Width=""63*"" />
 
1389
    <ColumnDefinition Width=""320*"" />
 
1390
  </Grid.ColumnDefinitions>
 
1391
  <Grid.RowDefinitions xmlns="""">
 
1392
    <RowDefinition />
 
1393
    <RowDefinition />
 
1394
    <RowDefinition />
 
1395
    <RowDefinition />
 
1396
    <RowDefinition />
 
1397
    <RowDefinition />
 
1398
    <RowDefinition />
 
1399
    <RowDefinition />
 
1400
  </Grid.RowDefinitions>
 
1401
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordTypedTitle"" Grid.Column=""1"" Grid.Row=""0"" xmlns="""" />
 
1402
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordExternalReference"" Grid.Column=""1"" Grid.Row=""1"" xmlns="""" />
 
1403
  <toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateCreated"" Grid.Column=""1"" Grid.Row=""2"" />
 
1404
  <toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateDue"" Grid.Column=""1"" Grid.Row=""3"" />
 
1405
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Author, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAuthor"" Grid.Column=""1"" Grid.Row=""4"" xmlns="""" />
 
1406
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Container, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordContainer"" Grid.Column=""1"" Grid.Row=""5"" xmlns="""" />
 
1407
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordIsEnclosed"" Grid.Column=""1"" Grid.Row=""6"" xmlns="""" />
 
1408
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAssignee"" Grid.Column=""1"" Grid.Row=""7"" xmlns="""" />
 
1409
  <TextBlock Grid.Column=""0"" Text=""Title (Free Text Part)"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""0"" xmlns="""" />
 
1410
  <TextBlock Grid.Column=""0"" Text=""External ID"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""1"" xmlns="""" />
 
1411
  <TextBlock Grid.Column=""0"" Text=""Date Created"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""2"" xmlns="""" />
 
1412
  <TextBlock Grid.Column=""0"" Text=""Date Due"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""3"" xmlns="""" />
 
1413
  <TextBlock Grid.Column=""0"" Text=""Author"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""4"" xmlns="""" />
 
1414
  <TextBlock Grid.Column=""0"" Text=""Container"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""5"" xmlns="""" />
 
1415
  <TextBlock Grid.Column=""0"" Text=""Enclosed?"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""6"" xmlns="""" />
 
1416
  <TextBlock Grid.Column=""0"" Text=""Assignee"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""7"" xmlns="""" />
 
1417
</Grid>";
 
1418
 
 
1419
      string json = JsonConvert.SerializeXNode(XDocument.Parse(xaml), Formatting.Indented);
 
1420
 
 
1421
      string expectedJson = @"{
 
1422
  ""Grid"": {
 
1423
    ""@xmlns"": ""http://schemas.microsoft.com/winfx/2006/xaml/presentation"",
 
1424
    ""@xmlns:x"": ""http://schemas.microsoft.com/winfx/2006/xaml"",
 
1425
    ""@xmlns:toolkit"": ""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"",
 
1426
    ""@Style"": ""{StaticResource trimFormGrid}"",
 
1427
    ""@x:Name"": ""TrimObjectForm"",
 
1428
    ""Grid.ColumnDefinitions"": {
 
1429
      ""ColumnDefinition"": [
 
1430
        {
 
1431
          ""@Width"": ""63*""
 
1432
        },
 
1433
        {
 
1434
          ""@Width"": ""320*""
 
1435
        }
 
1436
      ]
 
1437
    },
 
1438
    ""Grid.RowDefinitions"": {
 
1439
      ""@xmlns"": """",
 
1440
      ""RowDefinition"": [
 
1441
        null,
 
1442
        null,
 
1443
        null,
 
1444
        null,
 
1445
        null,
 
1446
        null,
 
1447
        null,
 
1448
        null
 
1449
      ]
 
1450
    },
 
1451
    ""TextBox"": [
 
1452
      {
 
1453
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1454
        ""@Text"": ""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"",
 
1455
        ""@Name"": ""RecordTypedTitle"",
 
1456
        ""@Grid.Column"": ""1"",
 
1457
        ""@Grid.Row"": ""0"",
 
1458
        ""@xmlns"": """"
 
1459
      },
 
1460
      {
 
1461
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1462
        ""@Text"": ""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"",
 
1463
        ""@Name"": ""RecordExternalReference"",
 
1464
        ""@Grid.Column"": ""1"",
 
1465
        ""@Grid.Row"": ""1"",
 
1466
        ""@xmlns"": """"
 
1467
      },
 
1468
      {
 
1469
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1470
        ""@Text"": ""{Binding Author, Converter={StaticResource trimPropertyConverter}}"",
 
1471
        ""@Name"": ""RecordAuthor"",
 
1472
        ""@Grid.Column"": ""1"",
 
1473
        ""@Grid.Row"": ""4"",
 
1474
        ""@xmlns"": """"
 
1475
      },
 
1476
      {
 
1477
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1478
        ""@Text"": ""{Binding Container, Converter={StaticResource trimPropertyConverter}}"",
 
1479
        ""@Name"": ""RecordContainer"",
 
1480
        ""@Grid.Column"": ""1"",
 
1481
        ""@Grid.Row"": ""5"",
 
1482
        ""@xmlns"": """"
 
1483
      },
 
1484
      {
 
1485
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1486
        ""@Text"": ""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"",
 
1487
        ""@Name"": ""RecordIsEnclosed"",
 
1488
        ""@Grid.Column"": ""1"",
 
1489
        ""@Grid.Row"": ""6"",
 
1490
        ""@xmlns"": """"
 
1491
      },
 
1492
      {
 
1493
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1494
        ""@Text"": ""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"",
 
1495
        ""@Name"": ""RecordAssignee"",
 
1496
        ""@Grid.Column"": ""1"",
 
1497
        ""@Grid.Row"": ""7"",
 
1498
        ""@xmlns"": """"
 
1499
      }
 
1500
    ],
 
1501
    ""toolkit:DatePicker"": [
 
1502
      {
 
1503
        ""@Style"": ""{StaticResource trimFormGrid_DP}"",
 
1504
        ""@Value"": ""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"",
 
1505
        ""@Name"": ""RecordDateCreated"",
 
1506
        ""@Grid.Column"": ""1"",
 
1507
        ""@Grid.Row"": ""2""
 
1508
      },
 
1509
      {
 
1510
        ""@Style"": ""{StaticResource trimFormGrid_DP}"",
 
1511
        ""@Value"": ""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"",
 
1512
        ""@Name"": ""RecordDateDue"",
 
1513
        ""@Grid.Column"": ""1"",
 
1514
        ""@Grid.Row"": ""3""
 
1515
      }
 
1516
    ],
 
1517
    ""TextBlock"": [
 
1518
      {
 
1519
        ""@Grid.Column"": ""0"",
 
1520
        ""@Text"": ""Title (Free Text Part)"",
 
1521
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1522
        ""@Grid.Row"": ""0"",
 
1523
        ""@xmlns"": """"
 
1524
      },
 
1525
      {
 
1526
        ""@Grid.Column"": ""0"",
 
1527
        ""@Text"": ""External ID"",
 
1528
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1529
        ""@Grid.Row"": ""1"",
 
1530
        ""@xmlns"": """"
 
1531
      },
 
1532
      {
 
1533
        ""@Grid.Column"": ""0"",
 
1534
        ""@Text"": ""Date Created"",
 
1535
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1536
        ""@Grid.Row"": ""2"",
 
1537
        ""@xmlns"": """"
 
1538
      },
 
1539
      {
 
1540
        ""@Grid.Column"": ""0"",
 
1541
        ""@Text"": ""Date Due"",
 
1542
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1543
        ""@Grid.Row"": ""3"",
 
1544
        ""@xmlns"": """"
 
1545
      },
 
1546
      {
 
1547
        ""@Grid.Column"": ""0"",
 
1548
        ""@Text"": ""Author"",
 
1549
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1550
        ""@Grid.Row"": ""4"",
 
1551
        ""@xmlns"": """"
 
1552
      },
 
1553
      {
 
1554
        ""@Grid.Column"": ""0"",
 
1555
        ""@Text"": ""Container"",
 
1556
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1557
        ""@Grid.Row"": ""5"",
 
1558
        ""@xmlns"": """"
 
1559
      },
 
1560
      {
 
1561
        ""@Grid.Column"": ""0"",
 
1562
        ""@Text"": ""Enclosed?"",
 
1563
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1564
        ""@Grid.Row"": ""6"",
 
1565
        ""@xmlns"": """"
 
1566
      },
 
1567
      {
 
1568
        ""@Grid.Column"": ""0"",
 
1569
        ""@Text"": ""Assignee"",
 
1570
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1571
        ""@Grid.Row"": ""7"",
 
1572
        ""@xmlns"": """"
 
1573
      }
 
1574
    ]
 
1575
  }
 
1576
}";
 
1577
 
 
1578
      Assert.AreEqual(expectedJson, json);
 
1579
 
 
1580
      XNode node = JsonConvert.DeserializeXNode(json);
 
1581
 
 
1582
      string xaml2 = node.ToString();
 
1583
 
 
1584
      string expectedXaml = @"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:toolkit=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"" Style=""{StaticResource trimFormGrid}"" x:Name=""TrimObjectForm"">
 
1585
  <Grid.ColumnDefinitions>
 
1586
    <ColumnDefinition Width=""63*"" />
 
1587
    <ColumnDefinition Width=""320*"" />
 
1588
  </Grid.ColumnDefinitions>
 
1589
  <Grid.RowDefinitions xmlns="""">
 
1590
    <RowDefinition />
 
1591
    <RowDefinition />
 
1592
    <RowDefinition />
 
1593
    <RowDefinition />
 
1594
    <RowDefinition />
 
1595
    <RowDefinition />
 
1596
    <RowDefinition />
 
1597
    <RowDefinition />
 
1598
  </Grid.RowDefinitions>
 
1599
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordTypedTitle"" Grid.Column=""1"" Grid.Row=""0"" xmlns="""" />
 
1600
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordExternalReference"" Grid.Column=""1"" Grid.Row=""1"" xmlns="""" />
 
1601
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Author, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAuthor"" Grid.Column=""1"" Grid.Row=""4"" xmlns="""" />
 
1602
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Container, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordContainer"" Grid.Column=""1"" Grid.Row=""5"" xmlns="""" />
 
1603
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordIsEnclosed"" Grid.Column=""1"" Grid.Row=""6"" xmlns="""" />
 
1604
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAssignee"" Grid.Column=""1"" Grid.Row=""7"" xmlns="""" />
 
1605
  <toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateCreated"" Grid.Column=""1"" Grid.Row=""2"" />
 
1606
  <toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateDue"" Grid.Column=""1"" Grid.Row=""3"" />
 
1607
  <TextBlock Grid.Column=""0"" Text=""Title (Free Text Part)"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""0"" xmlns="""" />
 
1608
  <TextBlock Grid.Column=""0"" Text=""External ID"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""1"" xmlns="""" />
 
1609
  <TextBlock Grid.Column=""0"" Text=""Date Created"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""2"" xmlns="""" />
 
1610
  <TextBlock Grid.Column=""0"" Text=""Date Due"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""3"" xmlns="""" />
 
1611
  <TextBlock Grid.Column=""0"" Text=""Author"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""4"" xmlns="""" />
 
1612
  <TextBlock Grid.Column=""0"" Text=""Container"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""5"" xmlns="""" />
 
1613
  <TextBlock Grid.Column=""0"" Text=""Enclosed?"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""6"" xmlns="""" />
 
1614
  <TextBlock Grid.Column=""0"" Text=""Assignee"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""7"" xmlns="""" />
 
1615
</Grid>";
 
1616
 
 
1617
      Assert.AreEqual(expectedXaml, xaml2);
 
1618
    }
 
1619
#endif
 
1620
 
 
1621
    [Test]
 
1622
    public void DeserializeXmlNodeDefaultNamespace()
 
1623
    {
 
1624
      string xaml = @"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:toolkit=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"" Style=""{StaticResource trimFormGrid}"" x:Name=""TrimObjectForm"">
 
1625
  <Grid.ColumnDefinitions>
 
1626
    <ColumnDefinition Width=""63*"" />
 
1627
    <ColumnDefinition Width=""320*"" />
 
1628
  </Grid.ColumnDefinitions>
 
1629
  <Grid.RowDefinitions xmlns="""">
 
1630
    <RowDefinition />
 
1631
    <RowDefinition />
 
1632
    <RowDefinition />
 
1633
    <RowDefinition />
 
1634
    <RowDefinition />
 
1635
    <RowDefinition />
 
1636
    <RowDefinition />
 
1637
    <RowDefinition />
 
1638
  </Grid.RowDefinitions>
 
1639
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordTypedTitle"" Grid.Column=""1"" Grid.Row=""0"" xmlns="""" />
 
1640
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordExternalReference"" Grid.Column=""1"" Grid.Row=""1"" xmlns="""" />
 
1641
  <toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateCreated"" Grid.Column=""1"" Grid.Row=""2"" />
 
1642
  <toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateDue"" Grid.Column=""1"" Grid.Row=""3"" />
 
1643
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Author, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAuthor"" Grid.Column=""1"" Grid.Row=""4"" xmlns="""" />
 
1644
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Container, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordContainer"" Grid.Column=""1"" Grid.Row=""5"" xmlns="""" />
 
1645
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordIsEnclosed"" Grid.Column=""1"" Grid.Row=""6"" xmlns="""" />
 
1646
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAssignee"" Grid.Column=""1"" Grid.Row=""7"" xmlns="""" />
 
1647
  <TextBlock Grid.Column=""0"" Text=""Title (Free Text Part)"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""0"" xmlns="""" />
 
1648
  <TextBlock Grid.Column=""0"" Text=""External ID"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""1"" xmlns="""" />
 
1649
  <TextBlock Grid.Column=""0"" Text=""Date Created"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""2"" xmlns="""" />
 
1650
  <TextBlock Grid.Column=""0"" Text=""Date Due"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""3"" xmlns="""" />
 
1651
  <TextBlock Grid.Column=""0"" Text=""Author"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""4"" xmlns="""" />
 
1652
  <TextBlock Grid.Column=""0"" Text=""Container"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""5"" xmlns="""" />
 
1653
  <TextBlock Grid.Column=""0"" Text=""Enclosed?"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""6"" xmlns="""" />
 
1654
  <TextBlock Grid.Column=""0"" Text=""Assignee"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""7"" xmlns="""" />
 
1655
</Grid>";
 
1656
 
 
1657
      XmlDocument document = new XmlDocument();
 
1658
      document.LoadXml(xaml);
 
1659
 
 
1660
      string json = JsonConvert.SerializeXmlNode(document, Formatting.Indented);
 
1661
 
 
1662
      string expectedJson = @"{
 
1663
  ""Grid"": {
 
1664
    ""@xmlns"": ""http://schemas.microsoft.com/winfx/2006/xaml/presentation"",
 
1665
    ""@xmlns:x"": ""http://schemas.microsoft.com/winfx/2006/xaml"",
 
1666
    ""@xmlns:toolkit"": ""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"",
 
1667
    ""@Style"": ""{StaticResource trimFormGrid}"",
 
1668
    ""@x:Name"": ""TrimObjectForm"",
 
1669
    ""Grid.ColumnDefinitions"": {
 
1670
      ""ColumnDefinition"": [
 
1671
        {
 
1672
          ""@Width"": ""63*""
 
1673
        },
 
1674
        {
 
1675
          ""@Width"": ""320*""
 
1676
        }
 
1677
      ]
 
1678
    },
 
1679
    ""Grid.RowDefinitions"": {
 
1680
      ""@xmlns"": """",
 
1681
      ""RowDefinition"": [
 
1682
        null,
 
1683
        null,
 
1684
        null,
 
1685
        null,
 
1686
        null,
 
1687
        null,
 
1688
        null,
 
1689
        null
 
1690
      ]
 
1691
    },
 
1692
    ""TextBox"": [
 
1693
      {
 
1694
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1695
        ""@Text"": ""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"",
 
1696
        ""@Name"": ""RecordTypedTitle"",
 
1697
        ""@Grid.Column"": ""1"",
 
1698
        ""@Grid.Row"": ""0"",
 
1699
        ""@xmlns"": """"
 
1700
      },
 
1701
      {
 
1702
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1703
        ""@Text"": ""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"",
 
1704
        ""@Name"": ""RecordExternalReference"",
 
1705
        ""@Grid.Column"": ""1"",
 
1706
        ""@Grid.Row"": ""1"",
 
1707
        ""@xmlns"": """"
 
1708
      },
 
1709
      {
 
1710
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1711
        ""@Text"": ""{Binding Author, Converter={StaticResource trimPropertyConverter}}"",
 
1712
        ""@Name"": ""RecordAuthor"",
 
1713
        ""@Grid.Column"": ""1"",
 
1714
        ""@Grid.Row"": ""4"",
 
1715
        ""@xmlns"": """"
 
1716
      },
 
1717
      {
 
1718
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1719
        ""@Text"": ""{Binding Container, Converter={StaticResource trimPropertyConverter}}"",
 
1720
        ""@Name"": ""RecordContainer"",
 
1721
        ""@Grid.Column"": ""1"",
 
1722
        ""@Grid.Row"": ""5"",
 
1723
        ""@xmlns"": """"
 
1724
      },
 
1725
      {
 
1726
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1727
        ""@Text"": ""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"",
 
1728
        ""@Name"": ""RecordIsEnclosed"",
 
1729
        ""@Grid.Column"": ""1"",
 
1730
        ""@Grid.Row"": ""6"",
 
1731
        ""@xmlns"": """"
 
1732
      },
 
1733
      {
 
1734
        ""@Style"": ""{StaticResource trimFormGrid_TB}"",
 
1735
        ""@Text"": ""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"",
 
1736
        ""@Name"": ""RecordAssignee"",
 
1737
        ""@Grid.Column"": ""1"",
 
1738
        ""@Grid.Row"": ""7"",
 
1739
        ""@xmlns"": """"
 
1740
      }
 
1741
    ],
 
1742
    ""toolkit:DatePicker"": [
 
1743
      {
 
1744
        ""@Style"": ""{StaticResource trimFormGrid_DP}"",
 
1745
        ""@Value"": ""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"",
 
1746
        ""@Name"": ""RecordDateCreated"",
 
1747
        ""@Grid.Column"": ""1"",
 
1748
        ""@Grid.Row"": ""2""
 
1749
      },
 
1750
      {
 
1751
        ""@Style"": ""{StaticResource trimFormGrid_DP}"",
 
1752
        ""@Value"": ""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"",
 
1753
        ""@Name"": ""RecordDateDue"",
 
1754
        ""@Grid.Column"": ""1"",
 
1755
        ""@Grid.Row"": ""3""
 
1756
      }
 
1757
    ],
 
1758
    ""TextBlock"": [
 
1759
      {
 
1760
        ""@Grid.Column"": ""0"",
 
1761
        ""@Text"": ""Title (Free Text Part)"",
 
1762
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1763
        ""@Grid.Row"": ""0"",
 
1764
        ""@xmlns"": """"
 
1765
      },
 
1766
      {
 
1767
        ""@Grid.Column"": ""0"",
 
1768
        ""@Text"": ""External ID"",
 
1769
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1770
        ""@Grid.Row"": ""1"",
 
1771
        ""@xmlns"": """"
 
1772
      },
 
1773
      {
 
1774
        ""@Grid.Column"": ""0"",
 
1775
        ""@Text"": ""Date Created"",
 
1776
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1777
        ""@Grid.Row"": ""2"",
 
1778
        ""@xmlns"": """"
 
1779
      },
 
1780
      {
 
1781
        ""@Grid.Column"": ""0"",
 
1782
        ""@Text"": ""Date Due"",
 
1783
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1784
        ""@Grid.Row"": ""3"",
 
1785
        ""@xmlns"": """"
 
1786
      },
 
1787
      {
 
1788
        ""@Grid.Column"": ""0"",
 
1789
        ""@Text"": ""Author"",
 
1790
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1791
        ""@Grid.Row"": ""4"",
 
1792
        ""@xmlns"": """"
 
1793
      },
 
1794
      {
 
1795
        ""@Grid.Column"": ""0"",
 
1796
        ""@Text"": ""Container"",
 
1797
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1798
        ""@Grid.Row"": ""5"",
 
1799
        ""@xmlns"": """"
 
1800
      },
 
1801
      {
 
1802
        ""@Grid.Column"": ""0"",
 
1803
        ""@Text"": ""Enclosed?"",
 
1804
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1805
        ""@Grid.Row"": ""6"",
 
1806
        ""@xmlns"": """"
 
1807
      },
 
1808
      {
 
1809
        ""@Grid.Column"": ""0"",
 
1810
        ""@Text"": ""Assignee"",
 
1811
        ""@Style"": ""{StaticResource trimFormGrid_LBL}"",
 
1812
        ""@Grid.Row"": ""7"",
 
1813
        ""@xmlns"": """"
 
1814
      }
 
1815
    ]
 
1816
  }
 
1817
}";
 
1818
 
 
1819
      Assert.AreEqual(expectedJson, json);
 
1820
 
 
1821
      XmlNode node = JsonConvert.DeserializeXmlNode(json);
 
1822
 
 
1823
      StringWriter sw = new StringWriter();
 
1824
      XmlWriter writer = XmlWriter.Create(sw, new XmlWriterSettings
 
1825
        {
 
1826
          Indent = true,
 
1827
          OmitXmlDeclaration = true
 
1828
        });
 
1829
      node.WriteTo(writer);
 
1830
      writer.Flush();
 
1831
 
 
1832
      string xaml2 = sw.ToString();
 
1833
 
 
1834
      string expectedXaml = @"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:toolkit=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"" Style=""{StaticResource trimFormGrid}"" x:Name=""TrimObjectForm"">
 
1835
  <Grid.ColumnDefinitions>
 
1836
    <ColumnDefinition Width=""63*"" />
 
1837
    <ColumnDefinition Width=""320*"" />
 
1838
  </Grid.ColumnDefinitions>
 
1839
  <Grid.RowDefinitions xmlns="""">
 
1840
    <RowDefinition />
 
1841
    <RowDefinition />
 
1842
    <RowDefinition />
 
1843
    <RowDefinition />
 
1844
    <RowDefinition />
 
1845
    <RowDefinition />
 
1846
    <RowDefinition />
 
1847
    <RowDefinition />
 
1848
  </Grid.RowDefinitions>
 
1849
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordTypedTitle"" Grid.Column=""1"" Grid.Row=""0"" xmlns="""" />
 
1850
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordExternalReference"" Grid.Column=""1"" Grid.Row=""1"" xmlns="""" />
 
1851
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Author, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAuthor"" Grid.Column=""1"" Grid.Row=""4"" xmlns="""" />
 
1852
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Container, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordContainer"" Grid.Column=""1"" Grid.Row=""5"" xmlns="""" />
 
1853
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordIsEnclosed"" Grid.Column=""1"" Grid.Row=""6"" xmlns="""" />
 
1854
  <TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAssignee"" Grid.Column=""1"" Grid.Row=""7"" xmlns="""" />
 
1855
  <toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateCreated"" Grid.Column=""1"" Grid.Row=""2"" />
 
1856
  <toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateDue"" Grid.Column=""1"" Grid.Row=""3"" />
 
1857
  <TextBlock Grid.Column=""0"" Text=""Title (Free Text Part)"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""0"" xmlns="""" />
 
1858
  <TextBlock Grid.Column=""0"" Text=""External ID"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""1"" xmlns="""" />
 
1859
  <TextBlock Grid.Column=""0"" Text=""Date Created"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""2"" xmlns="""" />
 
1860
  <TextBlock Grid.Column=""0"" Text=""Date Due"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""3"" xmlns="""" />
 
1861
  <TextBlock Grid.Column=""0"" Text=""Author"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""4"" xmlns="""" />
 
1862
  <TextBlock Grid.Column=""0"" Text=""Container"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""5"" xmlns="""" />
 
1863
  <TextBlock Grid.Column=""0"" Text=""Enclosed?"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""6"" xmlns="""" />
 
1864
  <TextBlock Grid.Column=""0"" Text=""Assignee"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""7"" xmlns="""" />
 
1865
</Grid>";
 
1866
 
 
1867
      Assert.AreEqual(expectedXaml, xaml2);
 
1868
    }
 
1869
 
 
1870
    [Test]
 
1871
    public void DeserializeAttributePropertyNotAtStart()
 
1872
    {
 
1873
      string json = @"{""item"": {""@action"": ""update"", ""@itemid"": ""1"", ""elements"": [{""@action"": ""none"", ""@id"": ""2""},{""@action"": ""none"", ""@id"": ""3""}],""@description"": ""temp""}}";
 
1874
 
 
1875
      XmlDocument xmldoc = JsonConvert.DeserializeXmlNode(json);
 
1876
 
 
1877
      Assert.AreEqual(@"<item action=""update"" itemid=""1"" description=""temp""><elements action=""none"" id=""2"" /><elements action=""none"" id=""3"" /></item>", xmldoc.InnerXml);
 
1878
    }
 
1879
  }
 
1880
}
 
1881
#endif
 
 
b'\\ No newline at end of file'