【发布时间】:2012-05-12 07:45:59
【问题描述】:
我有 C# 程序来生成 RDL 文件,以便在报告服务中显示报告。 我使用 Linq to Xml 生成 Xml。
当我尝试将 xmlns XAttribute 添加到报表元素时,我遇到了几个问题。
我测试了以下方法:
第一:
XDocument d = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("Report",
new XAttribute(XNamespace.Xmlns + "rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"),
new XAttribute(XNamespace.Xmlns + "cl", "http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition"),
new XAttribute("xmlns", "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"),
new XElement("DataSources", ""),
new XElement("DataSets", ""),
new XElement("ReportSections",
这是我的代码的一部分,展示了如何生成 xml:
秒:
XNamespace reportDef = "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";
XDocument d = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(reportDef + "Report",
new XAttribute(XNamespace.Xmlns + "rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"),
new XAttribute(XNamespace.Xmlns + "cl", "http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition"),
new XElement("DataSources", ""),
new XElement("DataSets", ""),
new XElement("ReportSections",...
第一种方法返回一个错误,第二种方法将属性 xmlns 添加到所有子节点。
我想要这种格式:
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
【问题讨论】:
标签: c# xml linq linq-to-xml xml-namespaces