# How Can I display XML file?

**URL:** <https://www.ruby-forum.com/t/how-can-i-display-xml-file/112400>\
**Category:** Ruby\
**Created:** [August 18, 2007, 12:21pm UTC](https://www.ruby-forum.com/t/how-can-i-display-xml-file/112400 "2007-08-18T12:21:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 18, 2007, 12:21pm UTC](https://www.ruby-forum.com/t/how-can-i-display-xml-file/112400/1 "2007-08-18T12:21:49Z")

</div>

Hi,friends,  
I have a XML string, such as xs="\<?xml version='1.0' ?\>\<test1  
1/\>\<test2 2/\>",how can I display(current window or a new window)  
it as XML like:  
âˆ’  
 1   
 2   
\</testh  
I wrote as following, but do not work:  
print “\<script language=“javascript”\>\nfunction t(){\n”  
print “document.write(’”,xs,"’);\n"  
print “}\nt();\n”  
or as:  
print “\n”  
print “winx=open(’’,‘XML’,‘menubar,scrollbars,resizeable’);\n”  
print “winx.document.writeln(‘xs’);\n”

Anyone knows it?  
Thanks

---

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 18, 2007, 12:23pm UTC](https://www.ruby-forum.com/t/how-can-i-display-xml-file/112400/2 "2007-08-18T12:23:23Z")

</div>

the xml string is xs="\<?xml version='1.0' ?\> 1  
 2 "

Thanks

---

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 18, 2007, 4:05pm UTC](https://www.ruby-forum.com/t/how-can-i-display-xml-file/112400/3 "2007-08-18T16:05:48Z")

</div>

Zhan feng Wang a Ã©crit :

> ```
> print "document.write('",xs,"');\n"
> print "}\nt();</script>\n"
> 
> ```
> 
> or as:  
> print “\n”  
> print “winx=open(’’,‘XML’,‘menubar,scrollbars,resizeable’);\n”  
> print “winx.document.writeln(‘xs’);\n”
> 
> Anyone knows it?  
> Thanks  
> You can use the Builder gem, to generate an indented xml stream.

Stef

---

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 18, 2007, 4:20pm UTC](https://www.ruby-forum.com/t/how-can-i-display-xml-file/112400/4 "2007-08-18T16:20:49Z")

</div>

Zhan feng Wang wrote:

> I have a XML string, such as xs="\<?xml version='1.0' ?\>\<test1  
> 1/\>\<test2 2/\>",how can I display(current window or a new window)  
> it as XML like:  
> ?  
> 1   
> 2

Use XSLT to convert the XML to XHTML describing the XML. This is a  
common  
XSLT application, and you should be able to find a sample script showing  
how.
