XML and javascript

Discussion in 'Javascript' started by ChefMo, Apr 22, 2008.

  1. ChefMo

    ChefMo Guest

    Any way to ruin javascript from inside of a .xml file?
    (<?xml-script...> or the like)
    ChefMo, Apr 22, 2008
    #1
    1. Advertising

  2. ChefMo

    Jeff North Guest

    On Mon, 21 Apr 2008 19:30:45 -0700 (PDT), in comp.lang.javascript
    ChefMo <>
    <>
    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.
    -- -------------------------------------------------------------
    : Remove your pants to reply
    -- -------------------------------------------------------------
    Jeff North, Apr 22, 2008
    #2
    1. Advertising

  3. 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
    Bart Van der Donck, Apr 22, 2008
    #3
  4. 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/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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Apr 22, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page