Connecting Tech Pros Worldwide Help | Site Map

Reading xml from hidden field using javascript

  #1  
Old June 30th, 2009, 10:26 AM
Newbie
 
Join Date: Jun 2009
Posts: 29
I want to read xml which is stored in hidden field using javascript
  #2  
Old June 30th, 2009, 10:31 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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
  #3  
Old June 30th, 2009, 10:43 AM
Newbie
 
Join Date: Jun 2009
Posts: 29

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
  #4  
Old June 30th, 2009, 10:50 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: Reading xml from hidden field using javascript


It's probably easier to read the XML file from the server.
  #5  
Old June 30th, 2009, 10:52 AM
Newbie
 
Join Date: Jun 2009
Posts: 29

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
  #6  
Old June 30th, 2009, 10:57 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: Reading xml from hidden field using javascript


if you're using a hidden field, you have a postback anyway.
  #7  
Old June 30th, 2009, 11:05 AM
Newbie
 
Join Date: Jun 2009
Posts: 29

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
  #8  
Old June 30th, 2009, 11:09 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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
  #9  
Old June 30th, 2009, 11:21 AM
Newbie
 
Join Date: Jun 2009
Posts: 29

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
  #10  
Old June 30th, 2009, 11:40 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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()]
  #11  
Old June 30th, 2009, 11:47 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,517
Provided Answers: 12

re: Reading xml from hidden field using javascript


For parsing and serializing XML, this is a good article.
  #12  
Old June 30th, 2009, 12:12 PM
Newbie
 
Join Date: Jun 2009
Posts: 29

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
  #13  
Old June 30th, 2009, 12:40 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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)?
  #14  
Old June 30th, 2009, 12:42 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,517
Provided Answers: 12

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?
  #15  
Old June 30th, 2009, 12:47 PM
Newbie
 
Join Date: Jun 2009
Posts: 29

re: Reading xml from hidden field using javascript


how to use ajax for my requirement as i explained in the above article
  #16  
Old June 30th, 2009, 12:55 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,517
Provided Answers: 12

re: Reading xml from hidden field using javascript


This is a useful article. If you get stuck, post your code.
  #17  
Old June 30th, 2009, 01:45 PM
Newbie
 
Join Date: Jun 2009
Posts: 29

re: Reading xml from hidden field using javascript


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help gunimpi answers 0 January 10th, 2007 08:55 PM
video in javascript chrisdude911 answers 8 March 28th, 2006 09:25 AM
Starting University COSC and learning JAVA, advice please :D David Van D answers 1 February 4th, 2006 02:45 AM
Repeating section control in ASP.NET Christoph Boget answers 11 November 18th, 2005 05:14 PM