I am writing a client .NET app and need to generate some reports. I would like to use HTML 5, CSS3 and JavaScript to generate reports that display tabular data and graphics by doing this:
- Generate a DataSet and save it as XML.
- Embed the XML data inside a predefined HTML page.
- Load the HTML page in the default browser.
- Using jQuery, parse the XML, and generate the necessary HTML elements to show a report.
- No Web server, just my client app.
I have read online that I shouldn’t embed XML data inside an HTML page, but this seems to work in the latest versions of all major browsers. My questions are:
- Any reason why I shouldn’t do this?
- If I shouldn’t do this, then do I have any other option to use the power of the local browser to generate reports?
There are many things that will work or run in a browser that aren’t necessarily supported. Unlike many server-side languages where a misplaced semicolon may cause your code to not compile, the browser is much more forgiving.
Thus, as a result, we end up with a world filled with fragmented websites that do not stand a chance against a W3C validator. We are given so much rope that we sometimes hang ourselves with it.
You recognize, based on your investigations and research, that XML can be embedded in HTML. Part of this success comes from the fact that HTML is a loose subset of XML; however, HTML has its own rules defined by a central committee that determines how browsers should implement their features.
The biggest risk that I see for you in using this strategy is this: Just because it works in today’s browsers doesn’t mean it will work in tomorrow’s browsers.
In other words, because embedding XML in HTML may not be in the spec, the browser vendors will not feel the need to continue supporting such a feature, which may have either resulted from a past feature that was removed from the spec, or just a freak accident resulting from HTML and XML’s similar roots.
I’m not sure why your idea works or if it is or isn’t in the spec, but I do know there are other solutions:
To answer your question of alternatives, take a look at XSLT, which is used to transform XML documents into valid HTML. This can be used without a Web server, as long as your app can serve both XML and XSLT files.