Reading xml from hidden field using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kirankumarn
    New Member
    • Jun 2009
    • 31

    Reading xml from hidden field using javascript

    I want to read xml which is stored in hidden field using javascript
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

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

    PS: questions should go in the answers section not in insights

    Comment

    • kirankumarn
      New Member
      • Jun 2009
      • 31

      #3
      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

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        It's probably easier to read the XML file from the server.

        Comment

        • kirankumarn
          New Member
          • Jun 2009
          • 31

          #5
          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

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            if you're using a hidden field, you have a postback anyway.

            Comment

            • kirankumarn
              New Member
              • Jun 2009
              • 31

              #7
              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

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                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

                Comment

                • kirankumarn
                  New Member
                  • Jun 2009
                  • 31

                  #9
                  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

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    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()]

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      For parsing and serializing XML, this is a good article.

                      Comment

                      • kirankumarn
                        New Member
                        • Jun 2009
                        • 31

                        #12
                        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

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          are you sure the XML is stored correctly (an attribute is usually not the proper place to store XML data)?

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            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?

                            Comment

                            • kirankumarn
                              New Member
                              • Jun 2009
                              • 31

                              #15
                              how to use ajax for my requirement as i explained in the above article

                              Comment

                              Working...