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 7708373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:35:45+00:00 2026-06-01T00:35:45+00:00

I have a string <ul><li e=100 n=50>Foo</li><li e=200 n=150>Bar</li></ul> and on client side I

  • 0

I have a string <ul><li e="100" n="50">Foo</li><li e="200" n="150">Bar</li></ul> and on client side I have to convert it to JSON. Something like {data:['Foo','Bar'],params:['100;50','200;150']}

I found a pretty good way to achieve it in here so my code should be something like that

var $input = $(input);
var data = "data:[";
var params = "params:[";

var first = true;
$input.find("li").each(function() {
    if (!first) {
        data += ",";
        params += ",";
    } else {
        first = false;
    }
    data += "'" + $(this).text() + "'";
    var e = $(this).attr("e");
    var n = $(this).attr("n");
    params += "'" + e + ';' + n + "'";
});

return "{data + "]," + params + "]}";

But the problem is that I can’t use jquery. How can I do the same thing with prototype?

  • 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-06-01T00:35:46+00:00Added an answer on June 1, 2026 at 12:35 am

    You want to use a DOM parser:

    https://developer.mozilla.org/en/DOMParser

    Something like this…

    var xmlStr = '<ul><li e="100" n="50">Foo</li><li e="200" n="150">Bar</li></ul>';
    
    var parser = new DOMParser();
    var doc = parser.parseFromString(xmlStr, "application/xml");
    
    var rootElement = doc.documentElement;
    var children = rootElement.childNodes;
    
    var jsonObj = {
        data: [],
        params: []
    };
    
    for (var i = 0; i < children.length; i++) {
        // I realize this is not how your implementation is, but this should give
        // you an idea of how to work on the DOM element
        jsonObj.data.push( children[i].getAttribute('e') );
        jsonObj.params.push( children[i].getAttribute('n') );
    }
    
    return jsonObj.toJSON();
    

    Also, don’t manually build your JSON string. Populate an object, then JSON-encode it.

    Edit: Note that you need to test for DOMParser before you can use it. Check here for how you can do that. Sorry for the W3Schools link.

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

Sidebar

Related Questions

I have text like: [100 ps] bar [139 ps] foo de fa fa [145
Hi I have a string of numbers separated by commas, 100,200,300,400,500 that I'm splitting
I have an array: string myArray={15,56,17-75,78,100-150,130} I want to filter myList by arrayElements .
I have string like \LESSING\root\cimv2:Win32_UserAccount.Domain=LESSING,Name=Admin How to convert it to LESSING\Admin using Framework?
I'd like to recover type information using reflection. I have public Foo(object coll, string
So, I have a file called 'dummy' which contains the string: There is 100%
I have the list with like 100,000 site link strings Each link is unique,
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I have a class Foo defined like this: class Foo { public: Foo(int num);
I have this code guile> (cairo-pdf-surface-create foo.pdf 100.0 100.0) ; and get this error

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.