locked
Reading and writing problem with XML document using Javascript RRS feed

  • Question

  • Hi,

     I am writing Below code for generating XML Document.
    <script type="text/javascript">
       function ReadXML()

         var fso  = new ActiveXObject("Scripting.FileSystemObject");
         var path="..\\XML\\book.xml";
         var fh;  
         
           fh = fso.CreateTextFile(path, true);
             
         fh.WriteLine("<?xml version='1.0' encoding='utf-8'?> ");
         fh.WriteLine("<editions>");
         fh.WriteLine("<Book>");
         fh.WriteLine("<edition>World Cooking Day</edition>");
         fh.WriteLine("</Book>");  
         fh.WriteLine("</editions>");
         fh.Close();

      Now i generated Below xml document (book.xml)

     <?xml version='1.0' encoding='utf-8'?>
    <editions>
    <Book>
    <edition>World Cooking Day</edition>
    </Book>
    </editions>


    i am using below code for Reading XML Document

    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
     xmlDoc.async="false";
     xmlDoc.load(path);


    To get Attribute length i am using below code.
    var x=xmlDoc.getElementsByTagName("Book");

    When i am trying to access node value, Attribute length Returns as 0.
    But in xml file i find there are one child node attribute and one parent Node attribute,But length is coming as 0.
    and I am not able to update XML File.
    To Udate XML File i am using below code
     
        var newel=xmlDoc.createElement("editor");
         var newtext=xmlDoc.createTextNode("firstName");
         newel.appendChild(newtext);
         x.appendChild(newel);

    Could you please any one help me, How to Access Attribute count and Update XML file using JavaScript.

     

    Thursday, September 24, 2009 8:29 AM