定义新 xml 文件时使用两个命名空间(XDocument、XElement、XAttribute)
XNamespace xnRD = "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner";
XNamespace xnNS = "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition";
XAttribute xaRD = new XAttribute(XNamespace.Xmlns + "rd", xnRD);
XAttribute xaNS = new XAttribute("xmlns", xnNS);
XElement x =
new XElement("Report", xaRD, xaNS,
new XElement("DataSources"),
new XElement("DataSets"),
new XElement("Body"),
new XElement("Width"),
new XElement("Page"),
new XElement("ReportID", xaRD),
new XElement("ReportUnitType", xaRD)
);
XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
doc.Add(x);
Console.WriteLine(doc.ToString());
导致运行时错误:
{"The prefix '' cannot be redefined from '' to 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition' within the same start element tag."}
我想做的只是将 DataSources 和 DataSets 写入 Debug.Console 来构建 ObjectDataSources,因为 VS2010 忽略了为 ASPX 添加它们。
编辑:
new XElement(xaRD + "ReportID"),
new XElement(xaRD + "ReportUnitType")
改变并得到:
Additional information: The ':' character, hexadecimal value 0x3A, cannot be included in a name.
相反
XNamespace xnRD = "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner";
XNamespace xnNS = "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition";
XAttribute xaRD = new XAttribute(XNamespace.Xmlns + "rd", xnRD);
XAttribute xaNS = new XAttribute("xmlns", xnNS);
XElement x =
new XElement("Report", xaRD, xaNS,
new XElement("DataSources"),
new XElement("DataSets"),
new XElement("Body"),
new XElement("Width"),
new XElement("Page"),
new XElement("ReportID", xaRD),
new XElement("ReportUnitType", xaRD)
);
XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
doc.Add(x);
Console.WriteLine(doc.ToString());
Results in runtime error:
{"The prefix '' cannot be redefined from '' to 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition' within the same start element tag."}
What I am trying to do is just make the DataSources and DataSets write out to the Debug.Console to build ObjectDataSources since VS2010 neglected to add them for ASPX.
EDIT:
new XElement(xaRD + "ReportID"),
new XElement(xaRD + "ReportUnitType")
Changed and got :
Additional information: The ':' character, hexadecimal value 0x3A, cannot be included in a name.
Instead
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this: