How to generate RDF/XML using a template in javascript? -


i have working javascript code generates rdf/xml document using variables picked html fields:

...   peopledoap += "   <foaf:name>" + person_name + "</foaf:name>\n";   if (person_url != "") {     peopledoap += "   <foaf:homepage rdf:resource=\"" + person_url + "/\"/>\n";   }   if (person_pic != "") {     peopledoap += "   <foaf:depiction rdf:resource=\"" + person_pic + "/\"/>\n";   } ... 

it's hard, looking @ code, sense of output (especially code scattered amongst sub functions etc).

i'm wondering if there easy way enable me have this:

... <foaf:name>%person_name%</foaf_name>   <foaf:homepage rdf:resource="%person_url%"/>   <foaf:depiction rdf:resource="%person_pic%"/> ... 

and substitution code. 1 slight complication if fields left blank, want not generate whole element. ie, if person_url='', above should generate as:

... <foaf:name>%person_name%</foaf_name>   <foaf:depiction rdf:resource="%person_pic%"/> ... 

i guess naively defining template huge string, performing bunch of replaces on it, there more elegant? mild preference native javascript rather libraries, happy convinced...

(btw, yes, since rdf/xml, maybe there smarter way using kind of rdf library. if want address of question instead, that's ok me.)

code here.

also, widget running on jetty server. don't think server-side code option.

i recommend using:

  1. jquery templates
  2. mustache
  3. john resig's micro-templating

jquery templates powerful , nicely integrated jquery. means can things this:

$.tmpl("hello ${n}", {n: "world"}).appendto('h1'); 

for simple stuff, or define templates in html inside special script tags custom mime types, compile them, populate them json data ajax calls, etc.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -