Using two namespaces when defining a new xml file (XDocument, XElement, XAttribute)

Posted by Manchuwook on Stack Overflow See other posts from Stack Overflow or by Manchuwook
Published on 2010-04-22T15:48:00Z Indexed on 2010/04/22 16:03 UTC
Read the original article Hit count: 376

Filed under:
|
|
|
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

© Stack Overflow or respective owner

Related posts about Xml

Related posts about reporting