By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,929 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,929 IT Pros & Developers. It's quick & easy.

XML and javascript

P: n/a
Any way to ruin javascript from inside of a .xml file?
(<?xml-script...or the like)
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Mon, 21 Apr 2008 19:30:45 -0700 (PDT), in comp.lang.javascript
ChefMo <mo************@gmail.com>
<bd**********************************@59g2000hsb.g ooglegroups.com>
wrote:
>| 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.
-- -------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
-- -------------------------------------------------------------
Jun 27 '08 #2

P: n/a
ChefMo wrote:
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);
}

---------------------------------

Hope this helps,

--
Bart
Jun 27 '08 #3

P: n/a
ChefMo wrote:
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/x...2008042202.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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.