Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display XML 1

Status
Not open for further replies.

flyclassic22

Technical User
Oct 1, 2002
54
0
0
SG
I need to create to display a output preview of a xml file of:

<?xml version=&quot;1.0&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;abc.xsl&quot;?>
<root>
<header>Welcome to my help page</header>
<body>Introduction. Welcome to our webpage.</body>
<copyright>Copyright 2002</copyright>
</root>

Anyone can guide me to use DOM, Javascript to display out all the elements but with some changes to it?
I would like to create a preview output to my page(not transform, just output that show all the tags as well) with/without a textarea that look like this:

<?xml version=&quot;1.0?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;abc.xsl&quot;?>
<root>
<header>Welcome ... </header>
<body>Introduction ...</body>
<copyright>Copyright ...</copyright>
</root>

that means it don't have to show all the values of the elements, just one word with 3 &quot;.&quot;. I can now only output everything with alert(objDOM.xml); but i need to modify abit adding &quot;...&quot; inside.
I've have no idea how to modify the value of the elements, however i now how to add new elements. Therefore i'm stucked.
Please help if possible...

Desperate...
 
Following code can help you


<html>
<head>
<SCRIPT LANGUAGE=javascript>
<!--

function showpreview(p)
{
var preview_xml=p;
var regX = /</g;
var regY = />/g;
var regZ = /\n/g;
//parent.previewframe.location.href=p;
var objDOM = new ActiveXObject(&quot;MSXML2.DOMDocument&quot;);
objDOM.load(preview_xml);
for(var i=0;i<objDOM.documentElement.childNodes.length;i++)
{
var obj=objDOM.documentElement.childNodes(i)
obj.text=obj.text + &quot;...&quot;
}
preview_xml=objDOM.xml.toString();
preview_xml=preview_xml.replace(regX,&quot;<&quot;);
preview_xml=preview_xml.replace(regY,&quot;>&quot;);
preview_xml=preview_xml.replace(regZ,&quot;<BR/>&quot;);
alert(preview_xml);
document.write(preview_xml);
}

//-->
</SCRIPT>
</head>
<%
dim xmldoc
' this file contains your xml
xmldoc=&quot;c:\\ss.xml&quot;
%>
<input type=button onclick=&quot;javascript:showpreview('<%=xmlDoc%>');&quot; value=&quot;Click here&quot;>
</html>
 
well, great to see that you can help me! I learn something from it.!

But using document.write the &quot;<&quot;&quot;>&quot; seems to be encoded in with IE6.

and also how can i only have the first word and then followed by &quot;...&quot; instead of the whole element value + &quot;...&quot;
?
thanks alot,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top