Solved

Showing XML gracefully.

Posted on 2002-05-16
6
530 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now