• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

Showing XML gracefully.

There is a stirng which is a xml file. and I want to show it on a new page gracefully.
I tried like below. unfortunately it won't work.

Thanks.

var res = "<?xml version ...> <bla><bla>... bla bla bla~ ";
var newWindow = window.open("","new");
newWindow.document.open("text/xml");
newWindow.document.write(res);
0
iamjhkang
Asked:
iamjhkang
  • 4
  • 2
1 Solution
 
b1xml2Commented:
what exactly do you mean by showing xml gracefully???
0
 
iamjhkangAuthor Commented:
What I mean is showing res on a new window.
and basically any pure XML is shown in a IE collapse-expand fashion.
0
 
b1xml2Commented:
ahhhhhhhh =)

first use a HTA file locally
=============================
displayXml.hta
=============================
<html>
<head>
<script language="javascript">
var oXML = new ActiveXObject("Microsoft.XMLDOM");
var oXSLT = new ActiveXObject("Microsoft.XMLDOM");
oXML.async = false;
oXML.loadXML("<?xml version='1.0'?><root><users total='10' /></root>");
oXSLT.async = true;
oXSLT.load("res://msxml.dll/defaultss.xsl");
window.onload = displayXml;

function displayXml() {
 if (oXSLT.readyState == 4) {
  var wWin = window.open("about:blank","displayXml");
  wWin.document.write(oXML.transformNode(oXSLT));
  wWin.document.close();
 } else {
  window.setTimeout("displayXml();",50);
 }
}
</script>
</head>
<body>Displaying XML Syntax</body>
</html>

Notes
=====
1. With the new changes in MSIE via the latest security packages, it may not be possible to load the defaultss.xsl from within the browser. This can be circumvented only by the user when the users settings have allow "Access Data Sources Across Domains".

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
b1xml2Commented:
You can even change the displayXml():

function displayXml() {
 if (oXSLT.readyState == 4) {
  var wWin = window.open("about:blank","displayXml","height=300,width=300,resizable=yes");
  wWin.document.write(oXML.transformNode(oXSLT));
  wWin.document.title = "XML Document";
  wWin.document.close();
 } else {
  window.setTimeout("displayXml();",50);
 }
}

Notes
=====
I forgot to mention that you need the Microsoft XML Parser.
0
 
iamjhkangAuthor Commented:
Thanks.

In my case xml(variable res) is just String type, so I like my way.
With some modification of the code below, it will work I think.

var res = "<?xml version ...> <bla><bla>... bla bla bla~ ";
var newWindow = window.open("","new");
newWindow.document.open("text/xml");
newWindow.document.write(res);

Again thanks.
0
 
b1xml2Commented:
I think you totally misunderstand how MSIE displays XML in such a contraction/expansion module.

And it has nothing to do with XML per se. Your code WILL NEVER WORK.

1. The code presented actually makes use of the defaultss.xsl which MSIE uses whenever it finds the HTTP Header's content type to be either text/xml or text/xsl. You can't set this via the document.open(), that will fail.

2. The code presented wraps the string into the XML DOM si that we can use the defaultss.xsl to perform the transformation to HTML in which case, the data is seen in a collapsible format.

3. The long and short of it is that if you want to open a new window and view any XML as the form that MSIE displays it and you are writing data to the window, you will have to use it this way, or write you own javascript modules that do it.

Thus, the display of XML in MSIE is due to the transform done via the defaultss.xsl document. On the client-side, writing code and expecting it to be displayed in the same format will require a transform.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now