I want to convert a single XML file into a human-readable format by JavaScript. Here is why:
- Need to generate a human readable-document that is going to work everywhere. (Windows, Mac, Linux, iPhone, Android, Blackberry, etc.)
- The information is coming out of a C++ data structure that I have defined.
- Need to be able to include pictures.
- This document would be sent as an email attachment once created.
I have looked into:
- XSLT: Can work as a single file, but only supported on the very newest mobile devices.
- CSS: I don’t think the formatting is sophisticated enough to get what I need.
- PDF: Open source library would have to be included into environment. I would prefer not to do this if there is a good alternative.
So that is why I am looking at JavaScript. But the first question is, can JavaScript format/display XML data that exists in the same file? If so, how?
You want to do something strange. You can’t use single JavaScript or CSS file as readable document with images. It’s just impossible. Why you don’t just use HTML? You can include CSS and JavaScript on HTML page and get almost any look and behaviour you want. HTML can be used as single file. Images can be included in HTML page using data:uri.