我有C#程序来生成RDL文件在报表服务中显示报表。 我使用Linq to Xml来生成Xml。将xmlns属性添加到根元素
当我尝试添加xmlns XAttribute到Report Element时,我遇到了几个问题。
我测试下面的方法:
第一:
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">
我用这个解决办法,但不幸的是因为在此之前属性添加到所有子节点。 –
似乎很奇怪,因为我无法重现这一点。尝试添加默认的命名空间属性,如我的第二个例子。也许更新你的问题,并显示更多的实际代码。 – Filburt
不幸的是,它像以前 –