How to include Javascript in xml-document?

前端 未结 7 1611
醉酒成梦
醉酒成梦 2020-12-01 07:59

The task seems to be pretty easy: how to include a Javascript file in xml-document so that at least Opera and Firefox could actually parse it and execute the code?

7条回答
  •  旧巷少年郎
    2020-12-01 08:40

    If I get you, you want an XML document to run javascript when viewed in a browser?

    This is not part of the XML standard, and as such will not be suppoted until it is (I assume this will never be supported because XML is not intended for display, but data). If you are talking about XHTML then this is a different matter.

    --

    Edit: just to clarify my answer.

    XML was never intended to be a display markup like HTML, thats why XHTML was developed (HTML that conforms to XML standards). Browsers have been made to interpret XHTML in a certain way, but XML is simply raw data.

    If you want your XML to run additions such as JavaScript you will want to consider using XSLT to transform your XML into XHTML and therefore take advantage of a browsers capabilities.

提交回复
热议问题