Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

***URGENT***writing XML using Javascript - InnerText

Status
Not open for further replies.

ufobaby

MIS
Sep 25, 2001
238
US
hi all, experts,

have got an assignmemt ->

using Javascript, CREATE an XMl document......hint:- use innerText property of HTML and xml property of DOMDocument.

now am not at all familir wiht JS or XML. can u help pls urgently.... by putting some code or something have only 4 days to complete this..

Regards
Niraj [noevil]
 
Here is some js code that transforms a xml document using an xsl:
Code:
function openDbInfo(dbname)
{
	var newWindow=window.open('','','toolbars=no, height=175, width=550')

	var objXml = new ActiveXObject("Microsoft.XMLDOM")
	objXml.async = false
	objXml.load("newoutput.xml")

	var theNode= "Server/Database[DatabaseName='"+dbname+"']";

	var objNode = objXml.selectSingleNode(theNode);

	var objXsl = new ActiveXObject("Microsoft.XMLDOM")
	objXsl.async = false
	objXsl.load("databaseInfo.xsl")	

	document.write(objNode.transformNode(objXsl))
	}

And here is some code that finds a particular row in the html document, counts the entries (options) and then uses innerHTML to insert the count

Code:
	var i 
	for(i=1; i<rows.length; i++)
	{	
		options =rows[i].getElementsByTagName('option');
		cells = rows[i].getElementsByTagName('td');
		optionCount = options.length - 1;
		
		if(optionCount < 0)
			optionCount = 0;
				
		rows[i].cells[2].innerHTML = optionCount;
	}
 
thanks Deeba,

But what i need is to create an XML file using JS and may be save it to the hard disk. and then comes u r code to read the same.I have some code from the net but this does not tell where the file gets saved.
------------- Here goes , any ideas ???? Please...
<HTML>
<HEAD>
<script language=javascript>
var doc = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
var root = doc.createElement(&quot;message&quot;);
doc.appendChild(root);
var child1 = doc.createElement(&quot;mymessage&quot;);
root.appendChild(child1);
child1.appendChild(doc.createTextNode( &quot;Hello&quot; ));
var attr = doc.createAttribute(&quot;id&quot;);
child1.setAttributeNode(attr);
attr.appendChild(doc.createTextNode( &quot;1&quot; ));
document.all.innerHTML = doc.documentElement.xml ;
doc.save(document);
//document.all.innerHTML = document.documentElement.innerText ;
//saving to file is not working.
</script>
<TITLE></TITLE>
</HEAD>
<BODY>
</BODY>
-------------------
Regards
Niraj [noevil]
 
Ok I've found the following code. Looks a lot like VBscript.
Here's the example:
Code:
function saveLocalData(theData){
  var newObj = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;)  
  var theFile = newObj.CreateTextFile(&quot;c:\\blah.txt&quot;, true)
  theFile.WriteLine(theData)
  theFile.Close()
}

you can put the writeline in a loop if you have lots of data to write in.

I hope this helps you!

~Deeba~
 
nah thats not it...

look at
and read about save() and all of the dom document object model.

if u are not worried about security on the page, you can just specify the path in the arguments for save i think.. eg

doc.save(&quot;c:\myfolder\wibble.xml&quot;);

otherwise if you are worried, just set the content type to xml and write the contents to the browser window by using

document.write(doc.xml);

and then force a save with jscript.

matt
 
Thanks, I was looking for something like that!
~Deeba
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top