logo

New Response

« Return to the blog entry

You are replying to:

    • avatar
    • randall
    • Posted on Sun 16 Nov 2008 02:27 AM

    i am writing a multi-browser xml lib. i came up with a fix for that to let me get string/number/bool results from IE with xpath queries. if someone knows how to get the current html source from document in IE, i bet this could be modified to work with the current document and applied by IE's behaviors.

    if you know how to do xml transoformations in IE you should be able to understand the following snippet. it returns a text output that js can convert. the FF source is there too for comparison:

    this.query=function(udef_xpath, udef_resultType){

    var result=false;

    if(!udef_resultType) var udef_resultType="string";

    if( browser.isIE()==true ){

    var tmpStyleSheet='';

    var p=this.asXML();

    var newXML=new erjXMLDocument( p );

    newXML.loadXSLDocument( tmpStyleSheet );

    var q=newXML.transform();

    newXML=null;

    switch(udef_resultType.toLowerCase()){

    case "number":

    result=parseFloat(q);

    break;

    case "bool":

    result=( (q.indexOf("TRUE") > -1) || (q.indexOf("true") > -1) || (q.indexOf("1") > -1) ? true : false );

    break;

    default:

    result=q;

    break;

    }

    }else{

    udef_resultType=( udef_resultType.toLowerCase().indexOf("number") > -1 ? XPathResult.NUMBER_TYPE : ( udef_resultType.toLowerCase().indexOf("bool") > -1 ? XPathResult.BOOLEAN_TYPE : XPathResult.STRING_TYPE ) );

    result=xmlDocument.evaluate( udef_xpath, xmlDocument, null, udef_resultType, null);

    switch(udef_resultType){

    case XPathResult.NUMBER_TYPE:

    result=result.numberValue;

    break;

    case XPathResult.BOOLEAN_TYPE:

    result=result.booleanValue;

    break;

    default:

    result=result.stringValue;

    break;

    }

    }

    return result;

    }

    --randall

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: