views:

231

answers:

2
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

A: 

Try this:

using System;
using System.Xml.Linq;

class Example
{
    static void Main()
    {
        XNamespace xnRD = "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner";
        XNamespace xnNS = "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition";

        XDocument doc = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                    new XElement(xnNS + "Report",
                    new XAttribute(XNamespace.Xmlns + "rd", xnRD),
                        new XElement("DataSources"),
                        new XElement("DataSets"),
                        new XElement("Body"),
                        new XElement("Width"),
                        new XElement("Page"),
                        new XElement(xnRD + "ReportID"),
                        new XElement(xnRD + "ReportUnitType")));

        Console.WriteLine(doc.ToString());
    }
}
Andrew Hare
Close<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition"> <DataSources xmlns="" /> <DataSets xmlns="" /> <Body xmlns="" /> <Width xmlns="" /> <Page xmlns="" /> <rd:ReportID /> <rd:ReportUnitType /></Report>
Manchuwook
A: 
Manchuwook