Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3988572
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:16:05+00:00 2026-05-20T06:16:05+00:00

I have some working Javascript code that generates an RDF/XML document using variables picked

  • 0

I have some working Javascript code that generates an RDF/XML document using variables picked up from 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 at this code, to get any sense of what the output will look like (especially as this code is scattered amongst sub functions etc).

I’m wondering if there is an easy way that would enable me to have something like this:

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

And then some substitution code. One slight complication is if fields are left blank, I will want to not generate the whole element. Ie, if person_url=”, the above should generate as:

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

I guess I could do this fairly naively by defining the template as a huge string, then performing a bunch of replaces on it, but is there anything more elegant? Mild preference for native Javascript rather than libraries, but happy to be convinced…

(Btw, yes, since this is RDF/XML, maybe there is a smarter way using some kind of RDF library. If you want to address that of the question instead, that’s ok with me.)

Code is here.

Also, this is a widget running on a Jetty server. I don’t think server-side code is an option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:16:06+00:00Added an answer on May 20, 2026 at 6:16 am

    I recommend using:

    1. jQuery Templates
    2. Mustache
    3. John Resig’s Micro-Templating

    jQuery Templates are very powerful and nicely integrated with jQuery. That means that you can do things like this:

    $.tmpl("Hello ${n}", {n: "World"}).appendTo('h1');
    

    for the most simple stuff, or define templates in your HTML inside special script tags with custom MIME types, compile them, populate them with JSON data from AJAX calls, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some JavaScript code that will read from the Google Maps API
I have some code I am working on that worked just fine until I
I have some working Javascript that manipulates the some DOM elements. The problem is,
I have some code that was working one month ago... now, when I check
I have some code that I would swear was working a month ago. However,
I have some JavaScript code that looks like: function statechangedPostQuestion() { //alert("statechangedPostQuestion"); if (xmlhttp.readyState==4)
I have some code that I am working on that has inline values such
I have some working code with a crutch to add BOM marker to a
I have some UIPopoverController that were working fine in 4.3/5.0 iOS iPad. Now, with
I have some issues with a PHP file that is not working properly. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.