want to add a new node in xml file using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • savitap
    New Member
    • May 2015
    • 4

    #1

    want to add a new node in xml file using javascript

    I have an image on page and there are some points are placed and one text area is assigned to them.I want to give the name to that points in text area and want to save that in XML file.
    and when we open the browser that name should should be there along with the point.

    I have done it almost only I cannot save that names in xml...
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I have done it almost
    please show us that code.

    Comment

    • savitap
      New Member
      • May 2015
      • 4

      #3
      Code:
      <!DOCTYPE html>
      <html>
      <head>
      <script src="loadxmldoc.js"> 
      </script>
      </head>
      <body>
      
      <script>
      xmlDoc=loadXMLDoc("one.xml");
      
      newNode=xmlDoc.createElement("book");
      
      x=xmlDoc.documentElement;
      y=xmlDoc.getElementsByTagName("book");
      
      document.write("Book elements before: " + y.length);
      document.write("<br>");
      x.insertBefore(newNode,y[3]);
      
      y=xmlDoc.getElementsByTagName("book");
      document.write("Book elements after: " + y.length);
      </script></body></html>
      Last edited by Dormilich; May 22 '15, 11:10 AM. Reason: please use code tags

      Comment

      • savitap
        New Member
        • May 2015
        • 4

        #4
        Its code for adding node but the error occured in .js file

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          what’s the error message?

          Comment

          • savitap
            New Member
            • May 2015
            • 4

            #6
            undefined loadXMLDoc()

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              then you should have a look into loadxmldoc.js how you load the file.

              Comment

              Working...