-Fixed converting emtpy XML elements with an array attribute not writing other attributes

This commit is contained in:
JamesNK
2011-05-02 11:25:06 +00:00
parent 045a1ec334
commit e04432b7e7
2 changed files with 39 additions and 1 deletions
@@ -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
@@ -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);
}