javascript - Parsing an xml template using jQuery -


so have template-like script i'm trying parse jquery. issue have tags want replace data, fine, want loop on object properties, makes more difficult.

i want rely on external libraries little possible, i'm using jquery here. know angular here don't know yet.

the template code looks this:

<?xml version="1.0" ?> <div id="test">     <each obj="list">         <div class="listdiv">             <span><value>thing</value></span>             <span><value>thing2</value></span>             <span><value>thing3</value></span>             <div>                 <each obj="morestuff">                     <span>blah: <value>blah</value></span>                     <span>foo: <value>foo</value></span>                 </each>             </div>         </div>     </each> </div> 

and want pass in following json object:

{     list: [         { thing: 3, thing2: 4, thing3: 5, morestuff: [{blah:1, foo:2},{blah:4, foo:6}] },         { thing: 1, thing2: 1, thing3: 2, morestuff: [{blah:4, foo:6}] }     ] } 

what want come out this:

<div id="test">     <div class="listdiv">         <span>3</span>         <span>4</span>         <span>5</span>         <div>             <span>blah: 1</span>             <span>foo: 2</span>             <span>blah: 4</span>             <span>foo: 6</span>         </div>     </div>     <div class="listdiv">         <span>1</span>         <span>1</span>         <span>2</span>         <div>             <span>blah: 4</span>             <span>foo: 6</span>         </div>     </div> </div> 

i getting work alright regular expressions of course it's cleaner dom manipulation , it's more extensible well. thing causes trouble recursive nature of <each> tags , fact <value> tags have data parent.

i've tried ton of ways every time either have recursion issue (infinite recursion , can't replace things) or can't pull data correctly. there way nicely?

have tried these jquery plugins

http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-an-introduction-to-jquery-templating/

https://github.com/trix/nano

http://knockoutjs.com/documentation/template-binding.html

http://www.jsviews.com/#samples/jsr/converters


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -