给定以下内容XDocument,初始化为变量xDoc:
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
<ReportSection>
<Width />
<Page>
</ReportSections>
</Report>
我在 XML 文件中嵌入了一个模板(我们称之为body.xml):
<Body xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
<ReportItems />
<Height />
<Style />
</Body>
我想把它作为一个孩子<ReportSection>。问题是如果通过添加它XElement.Parse(body.xml),它会保留命名空间,即使我认为应该删除命名空间(复制本身没有意义 - 已经在父级上声明)。如果我不指定命名空间,它会放置一个空的命名空间,所以它变成<Body xmlns="">.
有没有办法正确合并XElement到XDocument?我想在之后得到以下输出xDoc.Root.Element("ReportSection").AddFirst(XElement):
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
<ReportSection>
<Body>
<ReportItems />
<Height />
<Style />
</Body>
<Width />
<Page>
</ReportSections>
</Report>