By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,397 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,397 IT Pros & Developers. It's quick & easy.

Reading xml from hidden field using javascript

P: 31
I want to read xml which is stored in hidden field using javascript
Jun 30 '09 #1
Share this Question
Share on Google+
16 Replies


Dormilich
Expert Mod 5K+
P: 8,639
you can use the DOM to load the XML (see here).

PS: questions should go in the answers section not in insights
Jun 30 '09 #2

P: 31
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
Jun 30 '09 #3

Dormilich
Expert Mod 5K+
P: 8,639
It's probably easier to read the XML file from the server.
Jun 30 '09 #4

P: 31
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
Jun 30 '09 #5

Dormilich
Expert Mod 5K+
P: 8,639
if you're using a hidden field, you have a postback anyway.
Jun 30 '09 #6

P: 31
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
Jun 30 '09 #7

Dormilich
Expert Mod 5K+
P: 8,639
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
Jun 30 '09 #8

P: 31
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
Jun 30 '09 #9

Dormilich
Expert Mod 5K+
P: 8,639
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()]
Jun 30 '09 #10

acoder
Expert Mod 15k+
P: 16,027
For parsing and serializing XML, this is a good article.
Jun 30 '09 #11

P: 31
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
Jun 30 '09 #12

Dormilich
Expert Mod 5K+
P: 8,639
are you sure the XML is stored correctly (an attribute is usually not the proper place to store XML data)?
Jun 30 '09 #13

acoder
Expert Mod 15k+
P: 16,027
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?
Jun 30 '09 #14

P: 31
how to use ajax for my requirement as i explained in the above article
Jun 30 '09 #15

acoder
Expert Mod 15k+
P: 16,027
This is a useful article. If you get stuck, post your code.
Jun 30 '09 #16

P: 31
Thanks acoder & Dormilich for the suggestions this helped me a lot.
Jun 30 '09 #17

Post your reply

Sign in to post your reply or Sign up for a free account.