我有一个函数生成XML的列表对象:
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;
}
在 template.ToString()的内容如下:< rootElement的的xmlns =金塔:testTools>
在 XML 的内容如下:<例子><子元件GT; TESTDATA< /子元件GT;< /例>
在附加功能已执行的 template.ToString()的内容如下:< rootElement的的xmlns =金塔:testTools><实施例的xmlns =&GT ;<子元件GT; TESTDATA< /子元件GT;< /例>
After the add function has executed the template.ToString() reads: <RootElement xmlns="urn:testTools"><Example xmlns=""><SubElement>testData</SubElement></Example>
所以,出于某种原因,有一个空的空间增加,我怎么能这样做prevent呢?
So for some reason there was an empty namespace added, how can i prevent it from doing so?
设置的实例和子元素的元素的命名空间一样rootElement的。它被添加的xmlns =以清除该命名空间为这些元素。
Set the namespace on the Example and SubElement elements to the same as the RootElement. It is adding the xmlns="" to clear the namespace for these elements.