1

Is it possible to attach javascript to an XML file like in HTML ? (I am new to XML.)

Nikana Reklawyks
  • 3,233
  • 3
  • 33
  • 49
Varun Mehta
  • 1,733
  • 3
  • 18
  • 39
  • http://stackoverflow.com/questions/384639/how-to-include-javascript-in-xml-document –  Dec 07 '10 at 12:04
  • 2
    I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. – neo2862 Dec 07 '10 at 12:07

1 Answers1

2

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.

bobince
  • 528,062
  • 107
  • 651
  • 834
  • And any tool that understands XML Events, which is a general approach to attaching events to XML. – Abel Feb 07 '12 at 00:52