次の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>