XElement Add function adds xmlns="" to the XElement

Posted by JJoos on Stack Overflow See other posts from Stack Overflow or by JJoos
Published on 2010-02-19T10:22:36Z Indexed on 2010/04/23 22:43 UTC
Read the original article Hit count: 519

Filed under:
|
|
|
|

I have a function which generates xml for a list object:

public XDocument ToXML()
{
    foreach (var row in this)
    {
        var xml = row.ToXml();
        template.Root.Add(xml);
    }
    return template;
}

The template.ToString() reads: <RootElement xmlns="urn:testTools">

The xml reads: <Example><SubElement>testData</SubElement></Example>

After the add function has executed the template.ToString() reads: <RootElement xmlns="urn:testTools"><Example xmlns=""><SubElement>testData</SubElement></Example>

So for some reason there was an empty namespace added, how can i prevent it from doing so?

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml