XML dom to a file code....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • panos100m
    New Member
    • Aug 2007
    • 23

    XML dom to a file code....

    Hi the changes that i am making using dom (see function modify) take place only in memory untill the next reload ..but not in my xml file

    I am doing this for a customer and i am unable to install a
    server side language to do a submit , how can i save the contents of
    xmldoc directly to a file locally ?? I was thnking of active x , but can someone someone post some code? is that the best solution?



    Contents of xml file :



    <?xml version="1.0" encoding="UTF-8"?>
    <Global_Emergen cy activated="off" >
    <VDN id="000" Country="GR" ServiceName="CA ">
    <Training_Emerg ency>off</Training_Emerge ncy>
    <Languages number="0" InitLanguage="E N">
    <language/>
    <language/>
    <language/>
    </Languages>
    <Opening_Hour s>
    <General_Openin g_Hours>
    <day name="Monday" Open="08:00" Closed="17:00"/>
    </General_Opening _Hours>
    </Opening_Hours>
    <Menus>
    <Menu ID="MM" Name="Main Menu">
    <option name="PARTS" type="Transfer" enabled="false"/>
    </Menu>
    <Menu ID="CLUBUS" Name="CLUB_US" submenuof="MM">
    <option name="FORMS" type="Transfer" enabled="TRUE"> 22</
    option>
    </Menu>
    </Menus>


    HTML code:

    <html>
    <head>
    <script type="text/javascript" src="js/loadxmldoc.js">
    </script>



    <form method="POST" onsubmit="retur n modify();">
    <p>&nbsp;</p>


    <script type="text/javascript">


    function modify()


    {


    if (window.ActiveX Object)
    {
    xmlDoc=new ActiveXObject(" Microsoft.XMLDO M");


    }


    // code for Mozilla, Firefox, Opera, etc.
    else if (document.imple mentation.creat eDocument)
    {
    xmlDoc=document .implementation .createDocument ("","",null) ;

    }


    else
    {
    alert('Your browser cannot handle this script');

    }


    xmlDoc.async=fa lse;
    xmlDoc.load("co nfig.xml");

    y=xmlDoc.getEle mentsByTagName( 'Global_Emergen cy');


    alert ("we are in modify");
    alert (xmlDoc);
    //var x=xmlDoc.docume ntElement.getAt tribute('activa ted');

    //alert (x);

    for(i=0;i<y.len gth;i++)
    {
    alert (i);
    y.item(i).setAt tribute("activa ted","newvalue" );
    }

    for (i=0;i<y.length ;i++)
    {
    document.write( y[i].getAttribute(' activated'));
    document.write( "<br />");
    }
    //xmlDoc.document Element.setAttr ibute('activate d','newvalue');

    }


    function finalcheck()

    {
    alert ("hi");



    }


    function parseXML()
    {
    try
    {//try IE first
    xmlDoc=new ActiveXObject(" Microsoft.XMLDO M");
    }
    catch(e)
    {
    try
    {//try Mozilla, Firefox, Opera, etc.
    xmlDoc=document .implementation .createDocument ("","",null) ;
    }
    catch(e)
    {
    alert(e.message );
    return;
    }
    }
    xmlDoc.async=fa lse;
    xmlDoc.load("co nfig.xml");

    var y=xmlDoc.getEle mentsByTagName( "VDN");


    alert(y.length) ;


    var x=xmlDoc.docume ntElement.child Nodes;
    alert(x.length) ;
    var x=xmlDoc.docume ntElement.getAt tribute('activa ted');


    gedrop=document .getElementById ("GE");


    alert(x);


    /*
    for (var i=0; i< getdrop.options .length; i++)
    {


    alert (getdrop.option s[i].text.toUpperCa se() );
    /*
    if (getdrop.option s[i].[gedrop.selected Index].value==x)
    {
    // alert ("found");
    // alert (getdrop.option s[i].[gedrop.selected Index]);
    }
    */


    if (x=="off")
    {
    alert ("that works"); //do nothing



    }


    else

    {
    gedrop.selected Index=1;



    }


    /*

    if (gedrop.options[gedrop.selected Index].value==x)
    {
    alert ("index is"+gedrop.sele ctedIndex);


    alert ("found");



    }


    else
    {
    if (gedrop.options[gedrop.selected Index]==0)
    {gedrop.selecte dIndex=1};


    }


    */
    //document.getEle mentById('GE'). selectedIndex=
    /*
    =x;

    document.getEle mentById('dropd ownlistname').s elect edIndex =
    indexNumber
    alert (x);
    */


    /*
    document.getEle mentById("to"). innerHTML=
    xmlDoc.getEleme ntsByTagName("t o")[0].childNodes[0].nodeValue;
    document.getEle mentById("from" ).innerHTML=
    xmlDoc.getEleme ntsByTagName("f rom")[0].childNodes[0].nodeValue;
    document.getEle mentById("messa ge").innerHTM L=
    xmlDoc.getEleme ntsByTagName("b ody")[0].childNodes[0].nodeValue;


    */


    }


    </script>
    </head>

    <body onload="parseXM L()">
    <h1>Global Emergency <select size="1" id="GE" name="D1">
    <option value="off">Not Active</option>
    <option value="on">Acti ve</option>
    </select></h1>
    <p><input type="submit" value="Submit" name="B1"><inpu t
    type="button" onclick="modify ();" value="Button" name="B2"></p>
    </form>
    </body>
    </html>
  • panos100m
    New Member
    • Aug 2007
    • 23

    #2
    This is solved..
    I used active x to save the file and it works fine.

    Comment

    • icesh
      New Member
      • Mar 2008
      • 15

      #3
      hello,, I have same problem as panos100m..
      can anyone help me?
      how can we save the file using active x?
      thank you very much

      Comment

      Working...