动态生成 RDLC - 是什么阻止我使用 StringBuilder 来构建 XML
我正在建立一份本地报告。 由于隐藏属性的一些限制,我需要动态生成报告。
我在此处找到了一些文档。
ReportViewer 控件需要一个流。
我真的不喜欢文档中使用的方法。 在我看来,构建 XmlDocument 的可读性不是很好。
有什么东西阻止我这样做吗
班级计划 { 静态无效主(字符串[]参数) { 生成报告(); }
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();
}
}
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很简单:如果您使用该方法,处理器中的特殊操作会检测到错误的类用于生成该字符串,此时将调用正确性警察。
说真的,没有什么可以阻止你这样做。 事实上,在幕后,您可以打赌,更复杂的 XML 生成器中有一些代码可以执行非常类似的操作。 当您认真思考时,您会发现 XML 只是一个字符串,只要它格式良好,无论您如何构建它,该字符串都将是相同的。
其他类的优点是,当您想要构建更复杂的 XML 时,它们更简单、更灵活。
几乎有无限多个类可以生成 XML 或 XHTML。 寻找一个具有“流畅界面”的产品。 在类似 C++ 的语言中,它可能看起来像:
为了生成,
我在 这个问题中寻找类似的 HTML 内容。
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:
to generate
I was looking for something similar for HTML in this question.