Question

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();
    }
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top