If a node in the xml has a default namespace, and a child node re-declares the namespace but with a prefix, the nodes following the prefixed node will have the prefix but without the namespace definition.
Example:
var xmlString = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<root xmlns=""http://www.example.com/ns"">
<a/>
<bns:b xmlns:bns=""http://www.example.com/ns""/>
<c/>
</root>";
var xml = XElement.Parse(xmlString);
var json = JsonConvert.SerializeObject(xml);
This results in the following json:
{
"root": {
"@xmlns": "http://www.example.com/ns",
"a": null,
"bns:b": {
"@xmlns:bns": "http://www.example.com/ns"
},
"bns:c": null
}
}
Note how the c-child now has the "bns" prefix, but without the namespace declaration, making a conversion back to xml impossible (since the xml would be invalid).
Regards,
Espen