diff options
author | JamesNK <james@newtonking.com> | 2011-05-02 15:25:06 +0400 |
---|---|---|
committer | JamesNK <james@newtonking.com> | 2011-05-02 15:25:06 +0400 |
commit | e04432b7e7cd2284d866a8df8edc9ac6d73be6cc (patch) | |
tree | f6e74622f6e692ce409a4b00f52c8104de57c7e1 | |
parent | 045a1ec334421a2ac7df5db65fad68f85c297466 (diff) |
-Fixed converting emtpy XML elements with an array attribute not writing other attributes
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs | 38 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs b/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs index 3dfe29d..7fe895d 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs @@ -1219,6 +1219,44 @@ namespace Newtonsoft.Json.Tests.Converters ]
}", output);
}
+
+ [Test]
+ public void EmtpyElementWithArrayAttributeShouldWriteAttributes()
+ {
+ string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
+<root xmlns:json=""http://james.newtonking.com/projects/json"">
+<A>
+<B name=""sample"" json:Array=""true""/>
+<C></C>
+<C></C>
+</A>
+</root>";
+
+ XmlDocument d = new XmlDocument();
+ d.LoadXml(xml);
+
+ string json = JsonConvert.SerializeXmlNode(d, Formatting.Indented);
+
+ Assert.AreEqual(@"{
+ ""?xml"": {
+ ""@version"": ""1.0"",
+ ""@encoding"": ""utf-8""
+ },
+ ""root"": {
+ ""A"": {
+ ""B"": [
+ {
+ ""@name"": ""sample""
+ }
+ ],
+ ""C"": [
+ null,
+ null
+ ]
+ }
+ }
+}", json);
+ }
}
}
#endif
\ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs index 8c388df..bef5eb6 100644 --- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs @@ -961,7 +961,7 @@ namespace Newtonsoft.Json.Converters SerializeGroupedNodes(writer, node, manager, writePropertyName);
break;
case XmlNodeType.Element:
- if (IsArray(node) && node.ChildNodes.All(n => n.LocalName == node.LocalName))
+ if (IsArray(node) && node.ChildNodes.All(n => n.LocalName == node.LocalName) && node.ChildNodes.Count > 0)
{
SerializeGroupedNodes(writer, node, manager, false);
}
|