I had a quick search in stackoverflow.. but couldn't find anything quite what I was after.
I am trying to understand/get some pointers on how to build my own VERY simple templating engine for jQuery.
I basically have a standard AJAX call to get some XML (yes.. old fashioned I know.. and I will need to pull this into the JSON world perhaps). So I end up with say something like the following (just a cut down idea):
<rows>
<myFieldname1>some data</myFieldname1>
<myFieldname2>some data too</myFieldname2>
.. and so on ...
</rows>
So, for SINGLE based records, I have something I call 'PageDataMagic' (yes, very dramatic..) which, using jQuery, iterates through the XML and maps the xml node values to HTML elements (there is a bit of checking of course if an element is a checkbox etc..) - this is done by the XML nodes being called the fieldnames from the database / so as long as the ID's of the elements are named that way, it works.
Ok, on to the point.. if I want to have some sort of 'template' i.e. preferably an external JS / HTML, how would I go about dynamically mapping the fieldnames and dynamically adding a repeating template? I guess there is the append() function in jQuery? just I guess trying to read a template file and create row instances of that???
Does any of that make sense??? Maybe more coffee is needed...
Any help though very appreciated...
David.
--- EDIT ---
Oh yes, and right now it has to be XML because of some other constraints.. I know I could convert to JSON, and would make the whole process easier no doubt.. but I need to run from XML even if it has to parse that - bit slower..