Solved

Showing XML gracefully.

Posted on 2002-05-16
6
535 Views
Last Modified: 2008-02-01
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
Comment
Question by:iamjhkang
  • 4
  • 2
6 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 7015462
what exactly do you mean by showing xml gracefully???
0
 
LVL 1

Author Comment

by:iamjhkang
ID: 7015547
What I mean is showing res on a new window.
and basically any pure XML is shown in a IE collapse-expand fashion.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7015577
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 23

Expert Comment

by:b1xml2
ID: 7015583
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
 
LVL 1

Author Comment

by:iamjhkang
ID: 7015978
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
 
LVL 23

Accepted Solution

by:
b1xml2 earned 50 total points
ID: 7017926
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question