Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Showing XML gracefully.

Posted on 2002-05-16
6
Medium Priority
?
554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 200 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

636 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