-Fixed converting emtpy XML elements with an array attribute not writing other attributes
This commit is contained in:
@@ -1219,6 +1219,44 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
]
|
]
|
||||||
}", output);
|
}", 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
|
#endif
|
||||||
@@ -961,7 +961,7 @@ namespace Newtonsoft.Json.Converters
|
|||||||
SerializeGroupedNodes(writer, node, manager, writePropertyName);
|
SerializeGroupedNodes(writer, node, manager, writePropertyName);
|
||||||
break;
|
break;
|
||||||
case XmlNodeType.Element:
|
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);
|
SerializeGroupedNodes(writer, node, manager, false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user