We talked about XML in our previous post about how to generate and keep in LocalStorage for client side access.
Lets look at how we can deal with it from the browser using JavaScript and JQuery.
The LocalStorage is ready once the document is loaded.
Like so, we can iterate through the XML and process it as needed. If further clarification is needed, post it via comments. I am happy to write back.
Happy coding...
Lets look at how we can deal with it from the browser using JavaScript and JQuery.
$(document).ready(function(){
var swXmlDocumentAttrib = localStorage.getItem("swXmlDocumentAttrib");
var swXmlDocumentAttribJS = $.parseXML(swXmlDocumentAttrib);
$(swXmlDocumentAttribJS)
.find('AttributeItem')
.each(function(index, element){
var field = $(element)
var idConfigAttribute = field.find('idConfigAttribute').text()
var lbConfigAttribute = field.find('lbConfigAttribute').text()
});// end of swXmlDocumentAttribJS loop
});// end of document ready
The LocalStorage is ready once the document is loaded.
localStorage.getItem
This will retrieve the stored item with the given key.$.parseXML
Here we used JQuery to make it east to parse string to XMLAttributeItem
This is the item nameeach(function(index, element)
Each item has it's elements with index. This is a loop that iterates until it finishes the document reach the end of items.var idConfigAttribute = field.find('idConfigAttribute').text()
This get's the each element with matching key.Like so, we can iterate through the XML and process it as needed. If further clarification is needed, post it via comments. I am happy to write back.
Happy coding...
No comments:
Post a Comment