XML and javascript

C

ChefMo

Any way to ruin javascript from inside of a .xml file?
(<?xml-script...> or the like)
 
J

Jeff North

On Mon, 21 Apr 2008 19:30:45 -0700 (PDT), in comp.lang.javascript
ChefMo <[email protected]>
| Any way to ruin javascript from inside of a .xml file?
| (<?xml-script...> or the like)

Alot of people can ruin javascript without the need for xml :p

But seriously, XML is data only therefore can not run scripts.
-- -------------------------------------------------------------
(e-mail address removed) : Remove your pants to reply
-- -------------------------------------------------------------
 
B

Bart Van der Donck

ChefMo said:
Any way to ruin javascript from inside of a .xml file?
(<?xml-script...> or the like)

---------------------------------
XML:
---------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<root>
<jscode>alert('Hi from XML');</jscode>
</root>

---------------------------------
javascript:
---------------------------------

try {
x = new ActiveXObject('Microsoft.XMLDOM');
}
catch(e) {
try {
x = document.implementation.createDocument('', '', null);
}
catch(e) {
alert(e.message);
}
}

if (typeof(x) == 'object') {
x.async = false;
x.load('file.xml');
eval(x.getElementsByTagName('jscode')[0].childNodes[0].nodeValue);
}
 
M

Martin Honnen

ChefMo said:
Any way to ruin javascript from inside of a .xml file?
(<?xml-script...> or the like)

Well there are XML formats like XHTML or SVG which have a script
element. And with Mozilla or Opera you can put an XHTML script element
into other XML formats, a simple example is
http://home.arcor.de/martin.honnen/xml/test2008042202.xml.
However you are much better off in directly using HTML or XHTML for the
complete document, perhaps by transforming your XML to HTML or XHTML
using XSLT.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top