Testing for an XML parser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CES

    Testing for an XML parser

    All,
    Is their a way of testing if their is an XML parser installed and what the
    version number is with in JavaScript???
    Thanks in advance.
    CES


  • Martin Honnen

    #2
    Re: Testing for an XML parser



    CES wrote:
    [color=blue]
    > Is their a way of testing if their is an XML parser installed and what the
    > version number is with in JavaScript???[/color]

    If you are thinking about MS IE on Windows then you can test for Msxml e.g.

    <script type="text/jscript">
    var xmlDocument = null;
    var highestVersion = 0;
    var currentVersion;
    var versionStrings = [
    'Msxml2.DOMDocu ment.3.0',
    'Msxml2.DOMDocu ment.4.0',
    'Msxml2.DOMDocu ment.5.0',
    'Msxml2.DOMDocu ment.6.0',
    ];
    if (typeof ActiveXObject != 'undefined') {
    for (var v = 0; v < versionStrings. length; v++) {
    try {
    currentVersion = versionStrings[v];
    xmlDocument = new ActiveXObject(c urrentVersion);
    highestVersion = currentVersion;
    }
    catch (e) {
    break;
    }
    }
    }
    if (highestVersion ) {
    alert('Found support for ' + hightestVersion );
    }
    else {
    alert('No support for found.');
    }

    </script>

    The above should show the latest version of Msxml2.DOMDocum ent
    available. Note that it only checks for versions that implement the W3C
    XSLT and XPath 1.0 recommendation while there are earlier version like
    Msxml2.DOMDocum ent.2.6 and 2.0 I think which allow DOM scripting but are
    not compliant with the XSLT/XPath standards thus if you don't need
    XPath/XSLT you might want to check for the earlier version too.

    For DOM compliant implementations in browsers like Mozilla, Netscape 7
    or Opera 7 you could try DOM methods like hasFeature e.g.
    document.implem entation.hasFea ture('XML', '1.0')
    document.implem entation.hasFea ture('Core', '2.0')
    but only Mozilla thinks it has enough support to yield true on those
    both while Opera 7.50 even for 1.0 returns false.

    Other than that I am not sure what you have in mind with a version number.

    --

    Martin Honnen


    Comment

    Working...