...

View Full Version : how to break a line in xml file using javascript?



natzjordaan
01-06-2012, 08:02 AM
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

Old Pedant
01-06-2012, 08:19 AM
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.

natzjordaan
01-06-2012, 08:28 AM
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;
}

natzjordaan
01-06-2012, 12:39 PM
Old Pedant? Did you get my reply?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum