Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to break a line in xml file using javascript?

    Hey guys

    I export data from Javascript to Xml file. I have tried several ways to break a line in xml file like document.write("<br/>"); or document.writeln(); etc, but seem it is impossible.

    Maybe you can give me a solution......

    Look at below:

    XML File:

    <?xml version="1.0"?>
    <DATA>
    <Cust><Select>Debit Card</Select></Cust><Cust>[User>Jan</User></Cust><DATA>

    I want to break <Cust> from another <Cust>.

    Javascript:

    function ok_click() {
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
    xmlDoc.async = false;
    xmlDoc.load("data.xml");
    if (xmlDoc.readyState == 4 && xmlDoc.parseError.errorCode == 0) {
    var root = xmlDoc.documentElement;

    var e1 = document.getElementById("Select1");
    var _account_type = xmlDoc.createTextNode(e1.options[e1.selectedIndex].value);

    var e2 = document.getElementById("Select2");
    var _user = xmlDoc.createTextNode(e2.options[e2.selectedIndex].value);


    var account_type = xmlDoc.createNode(1, "Select", "");
    var user = xmlDoc.createNode(1, "User", "");


    account_type.appendChild(_account_type);
    user.appendChild(_user);


    var cust = xmlDoc.createNode(1, "Cust", "");

    cust.appendChild(account_type);
    document.write("<br/>");
    cust.appendChild(user);


    root.appendChild(cust);

    SaveXML(xmlDoc, "data.xml");
    alert("Save!");
    }
    }

    Your help would much appreciated

    Thanks
    Natz

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    You don't show your SaveXML() function's code. That's where you would have to put in the line breaks, as it writes the data to the file.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for reply Yes I have also tried on SAVE function. It is still not solved.

    Look at below:

    function SaveXML(xmlDoc, filename) {
    var outputXML = new String(xmlDoc.xml);
    var mfObj = new ActiveXObject("Scripting.FileSystemObject");
    var absPath = getPath();
    var file = mfObj.CreateTextFile(absPath + filename, true);
    file.Write(outputXML);
    file.Close();
    }

    function getPath() {
    var path = document.location;
    var str = new String(path);
    var end = str.lastIndexOf("/");
    var absolutePath = str.substring(8, end) + "/";
    absolutePath = absolutePath.replace(/%20/g, " ");
    return absolutePath;
    }

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Old Pedant? Did you get my reply?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •