Dynamically creating RDLC - what's stopping me from using StringBuilder to build XML

I am creating a local report. Due to some limitations of the Hidden property, I need to generate the report dynamically.

I found the documentation here .

The ReportViewer controller requires a stream.

I don't like the method used in the documentation. And the creation of the XmlDocument is not 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 source to share


1 answer


Simple: if you use this method, special operations in the processor detect that Wrong Class ws is being used to create this string, and then the Correct Police is called.

Seriously, there is nothing stopping you from doing it that way; in fact, under the covers, you can bet there is some code in a more complex XML generator that does something very similar. When you go to it, the XML is just a string, and as long as it is well formed, this string will be the same no matter how you create it.

The other classes have the advantage of being simpler and more flexible if you want to create more complex XML.


There are almost infinitely many classes that can generate XML or XHTML. Look for one that has a "free interface". In C ++, it might look like this:



  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 .

+1


a source







All Articles