Connecting Tech Pros Worldwide Help | Site Map

Reading xml from hidden field using javascript

Newbie
 
Join Date: Jun 2009
Posts: 31
#1: Jun 30 '09
I want to read xml which is stored in hidden field using javascript
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Jun 30 '09

re: Reading xml from hidden field using javascript


you can use the DOM to load the XML (see here).

PS: questions should go in the answers section not in insights
Newbie
 
Join Date: Jun 2009
Posts: 31
#3: Jun 30 '09

re: Reading xml from hidden field using javascript


I tried with DOM but the problem is I am not able to read the xml from hidden field. I want to use this functionality because I will get xml using ds.GetXml() from codebehind & i store in hidden field so that i can access using javascript. This i want to use for listbox manipulation purposes. Thanks in advance
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#4: Jun 30 '09

re: Reading xml from hidden field using javascript


It's probably easier to read the XML file from the server.
Newbie
 
Join Date: Jun 2009
Posts: 31
#5: Jun 30 '09

re: Reading xml from hidden field using javascript


but after manipulations of xml I want to store or retain the changes made in xml so i want to store it again using hidden field so that postback is avoided
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#6: Jun 30 '09

re: Reading xml from hidden field using javascript


if you're using a hidden field, you have a postback anyway.
Newbie
 
Join Date: Jun 2009
Posts: 31
#7: Jun 30 '09

re: Reading xml from hidden field using javascript


I will explain purpose: I have 4 list boxes i.e., two available & two selected listboxes (ie., 2 listboxes on top one available & another selected listboxes side to side similarly another two below it). if i select an item in the selected listbox on the top the respective item will be loaded in the below selected listboxes where i can remove the items of the selected item. this type of functionality i was handling in codebehind & i was storing in viewstate, but i want to do this in xml & javascript using hidden field for storing purposes. so that i can recall the changes if i store in hidden field so that process will be fast
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#8: Jun 30 '09

re: Reading xml from hidden field using javascript


a) as long as you don't leave the page, the XML will be stored in cache by javascript

b) have to read it again a couple of times and think it over
Newbie
 
Join Date: Jun 2009
Posts: 31
#9: Jun 30 '09

re: Reading xml from hidden field using javascript


thanks for the reply but i get xml from codebehind using ds.GetXml() method i don't want to create an xml file for this for only reading the xml file so i want to store in hidden field. can u pls tell me other methods so that i can read the xml without creating the xml file pls thanks in advance for you are feedback
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#10: Jun 30 '09

re: Reading xml from hidden field using javascript


is this XML file submitted with the form (or rather, it is used in form processing)? (if you don't process the data on the server, there is no need for writing the data into the page)

if you already have the XML (be it a string or a document tree) you certainly don't need a file to read it from. you should be able to directly operate on the XML with DOM. [well, I don't know anything about ds.GetXml()]
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#11: Jun 30 '09

re: Reading xml from hidden field using javascript


For parsing and serializing XML, this is a good article.
Newbie
 
Join Date: Jun 2009
Posts: 31
#12: Jun 30 '09

re: Reading xml from hidden field using javascript


I want to read the xml which is stored in hidden field using javascript for me DOM is not working, i am not able to read the xml which i stored in hidden field
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#13: Jun 30 '09

re: Reading xml from hidden field using javascript


are you sure the XML is stored correctly (an attribute is usually not the proper place to store XML data)?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#14: Jun 30 '09

re: Reading xml from hidden field using javascript


Firstly, how are you storing the XML in the hidden field? Can you show the code for that? It will be in string format, so you will need to use a parser to parse the string into XML format.

If you want to avoid a "postback", use Ajax. Then there's no need to store the XML in a hidden field. If you don't want to use Ajax and you store all of the data in XML, even then a hidden field is not required. Did you read the link I posted earlier?
Newbie
 
Join Date: Jun 2009
Posts: 31
#15: Jun 30 '09

re: Reading xml from hidden field using javascript


how to use ajax for my requirement as i explained in the above article
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#16: Jun 30 '09

re: Reading xml from hidden field using javascript


This is a useful article. If you get stuck, post your code.
Newbie
 
Join Date: Jun 2009
Posts: 31
#17: Jun 30 '09

re: Reading xml from hidden field using javascript


Thanks acoder & Dormilich for the suggestions this helped me a lot.
Reply