Reputation: 1753
Is it possible to attach javascript to an XML file like in HTML ? (I am new to XML.)
Upvotes: 1
Views: 270
Reputation: 536795
Only in XML-based languages that have a specific mechanism for attaching javascript.
eg. XHTML:
<html xmlns="http://www.w3.org/1999/xhtml">
...
<script type="text/javascript" src="..."></script>
or SVG:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
...
<script type="application/ecmascript" xlink:href="..."/>
For generic XML, you would have to use an <?xml-stylesheet
to transform it into one of those languages to get the ability to include a script. (There are also extensions to XSLT in some implementations that can execute script as part of the transformation process, but I'm guessing that's not what you're after.)
Otherwise, plain XML, as viewed in a browser's generic XML viewer, does not have the ability to script.
Upvotes: 2