When I add new nodes to the root of a node that has a namespace defined, subsequent nodes added all receive xmlns="" attached to to them. This is the code that shows my problem:
void Main()
{
var xdoc = new XDocument();
var shipmentRoot = new XElement("{someNS}Shipment");
var newElement = new XElement("ContainerCollection", new XElement("Container", new XElement("ContainerNumber", "42")));
newElement.SetAttributeValue("Content", "Partial");
shipmentRoot.Add(newElement);
xdoc.Add(shipmentRoot);
xdoc.Dump();
}
Generates this XML:
<Shipment xmlns="someNS">
<ContainerCollection Content="Partial" xmlns="">
<Container>
<ContainerNumber>42</ContainerNumber>
</Container>
</ContainerCollection>
</Shipment>
My desired XML would be:
<Shipment xmlns="someNS">
<ContainerCollection Content="Partial">
<Container>
<ContainerNumber>42</ContainerNumber>
</Container>
</ContainerCollection>
</Shipment>