views:

399

answers:

2

Hi

I'm building a Local Report. Because of some limitations of the Hidden property, I need to dynamically generate the report.

I found some documentation here.

The ReportViewer Control needs a stream.

I don't really like the method that's used in the documentation. And building an XmlDocument isn't very readable imo.

Is there something stopping me from doing it like this

class Program { static void Main(string[] args) { GenerateReport(); }

    static void GenerateReport(){        
        StringBuilder reportXml = new StringBuilder();

        reportXml.Append("<Report>");
        reportXml.Append("<PageHeight>8.5in</PageHeight>");            
        reportXml.Append("</Report>");          

        XmlDocument xmlDocument = new XmlDocument();

        xmlDocument.LoadXml(reportXml.ToString());

        xmlDocument.Save(@"C:\test.xml");
        xmlDocument.Save(Console.Out);

        Console.ReadLine();
    }
}
+1  A: 

Simple: if you use that method, special operations in the processor detect that the Wrong Class ws used to generate that string, at which point the Correctness Police are called.

Seriously, there's nothing that keeps you from doing it exactly that way; in fact, under the covers you can bet there is some code in the more complicated XML generator that does something very much like that. When you get down to it, XML is just a string, and as long as it's well-formed, that string is going to be the same no matter how you build it.

The advantage of other classes is that they're simpler and more flexible when you want to build more complicated XML.


There are nearly infinitely many classes that can generate XML or XHTML. Look for one that has a "fluent interface". In a C++-like language it might look like:

  XMLOutStream foo("filename.xml);
  foo.group("Top","attr=val")
     .group("Next")
     .line("Another", "attr=val") ;

to generate

 <Top>
   <Next attr="val">
      <Another attr="val" />
   </Next>
 </Top>

I was looking for something similar for HTML in this question.

Charlie Martin
Well this is just a little sample, the actual Xml I'm about to build is gonna be more complex and larger. But is it me or is doing it this way more readable than using the other classes.
It sure can be. I'd look about for other classes.
Charlie Martin
A: 

If you want an easy way out, take a look at www.rptgen.com. This RDLC generator will write all of the XML for you. Just pass it our DataTable and your done.

Hope this helps Myron Joy

Myron Joy