I manage to show XML using -
wxml = window.open("my_template.xml", "my_xml" );
I manage to change the DOM using -
xDoc = wxml.document;
xNodes = xExDoc.getElementsByTagName("myNodeName");
xValue = xNodes[i].getElementsByTagName("value")[0];
xValue.firstChild.nodeValue = nodeNewVal;
But I do not manage to see the new DOM values on the screen.
How can I force "Refresh screen by DOM" ?
Note: reload() would not help, because it loads the original page, and I want to see the page with the DOM changes.
Edit - the code I use:
XML file (my_template.xml):
<myXmlRoot>
<device>
<input><name>"name 1"</name><value>{replaceMe!}</value></input>
<input><name>"name 2"</name><value>{replaceMe!}</value></input>
</device>
<device>
<input><name>"name 1"</name><value>{replaceMe!}</value></input>
<input><name>"name 2"</name><value>{replaceMe!}</value></input>
</device>
<device>
<input><name>"name 1"</name><value>{replaceMe!}</value></input>
<input><name>"name 2"</name><value>{replaceMe!}</value></input>
</device>
</myXmlRoot>
HTML file:
<html>
<head>
<title>Open XML in External Window</title>
</head>
<body>
<button onClick="fShowXmlInExternalWin()">Show XML </button> (does not show the updated version on the screen)
<script type="text/javascript" >
var wxml;
var xDoc;
var xDevices, xInputs;
var xDevice, xInput;
function fSetXmlAInput(iDevice, iNode, nodeNewVal) {
xInput = xInputs[iNode];
xValue = xInput.getElementsByTagName("value")[0];
// change node value:
// console.log("nodeVal: " + xValue.firstChild.nodeValue);
xValue.firstChild.nodeValue = nodeNewVal;
// console.log("newVal: " + xValue.firstChild.nodeValue);
}
function fSetXmlDevice(iDevice) {
xDevice = xDevices[iDevice];
xInputs = xDevice.getElementsByTagName("input");
fSetXmlAInput(iDevice, 0, "22");
fSetXmlAInput(iDevice, 1, "33");
}
function fShowXmlInExternalWin() {
wxml = window.open("my_template.xml", "my_xml" );
xDoc = wxml.document;
xDevices = xDoc.getElementsByTagName("device");
fSetXmlDevice(1);
return false;
}
</script>
</body>
</html>
On first view you have the following error:
I don't see xExDoc defined somewhere in your code...I only see xDoc.
Update:
In addition, your i variable is not defined causing another error. Also, you should use firebug to debug the code step by step or as a minimum add
in order to check how many tags are found.
Update 2: (includes solution)
I've found two possible options:
Option 1 keeps XML browser formatting intact while option 2 causes the browser to view the XML as not xml content any more and the formatting is lost.
Code is below:
Update 3:
Using document.open and document.write on the new window works in IE to output the correct XML but the XML rendering is off - seems to render the content as HTML...