⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 overview-summary-sarissa.js.html

📁 sarissa用于支持多浏览器的浏览及编程
💻 HTML
📖 第 1 页 / 共 4 页
字号:
    _SARISSA_DOM_PROGID = null;    _SARISSA_THREADEDDOM_PROGID = null;    _SARISSA_XSLTEMPLATE_PROGID = null;    _SARISSA_XMLHTTP_PROGID = null;    <span class="reserved">if</span>(!window.XMLHttpRequest){        <span class="comment">/**         * Emulate XMLHttpRequest         * <span class="attrib">@constructor</span>         */</span>        XMLHttpRequest = <span class="reserved">function</span>() {            <span class="reserved">if</span>(!_SARISSA_XMLHTTP_PROGID){                _SARISSA_XMLHTTP_PROGID = Sarissa.pickRecentProgID([<span class="literal">"Msxml2.XMLHTTP.6.0"</span>, <span class="literal">"MSXML2.XMLHTTP.3.0"</span>, <span class="literal">"MSXML2.XMLHTTP"</span>, <span class="literal">"Microsoft.XMLHTTP"</span>]);            };            <span class="reserved">return</span> new ActiveXObject(_SARISSA_XMLHTTP_PROGID);        };    };    <span class="comment">// we dont need this anymore</span>    <span class="comment">//============================================</span>    <span class="comment">// Factory methods (IE)</span>    <span class="comment">//============================================</span>    <span class="comment">// see non-IE version</span>    Sarissa.getDomDocument = <span class="reserved">function</span>(sUri, sName){        <span class="reserved">if</span>(!_SARISSA_DOM_PROGID){            _SARISSA_DOM_PROGID = Sarissa.pickRecentProgID([<span class="literal">"Msxml2.DOMDocument.6.0"</span>, <span class="literal">"Msxml2.DOMDocument.3.0"</span>, <span class="literal">"MSXML2.DOMDocument"</span>, <span class="literal">"MSXML.DOMDocument"</span>, <span class="literal">"Microsoft.XMLDOM"</span>]);        };        var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);        <span class="comment">// if a root tag name was provided, we need to load it in the DOM object</span>        <span class="reserved">if</span> (sName){            <span class="comment">// create an artifical namespace prefix </span>            <span class="comment">// or reuse existing prefix if applicable</span>            var prefix = <span class="literal">""</span>;            <span class="reserved">if</span>(sUri){                <span class="reserved">if</span>(sName.indexOf(<span class="literal">":"</span>) &gt; 1){                    prefix = sName.substring(0, sName.indexOf(<span class="literal">":"</span>));                    sName = sName.substring(sName.indexOf(<span class="literal">":"</span>)+1);                 }<span class="reserved">else</span>{                    prefix = <span class="literal">"a"</span> + (_sarissa_iNsCounter++);                };            };            <span class="comment">// use namespaces if a namespace URI exists</span>            <span class="reserved">if</span>(sUri){                oDoc.loadXML(<span class="literal">'&lt;'</span> + prefix+<span class="literal">':'</span>+sName + <span class="literal">" xmlns:"</span> + prefix + <span class="literal">"=\"</span><span class="literal">" + sUri + "</span>\<span class="literal">""</span> + <span class="literal">" /&gt;"</span>);            } <span class="reserved">else</span> {                oDoc.loadXML(<span class="literal">'&lt;'</span> + sName + <span class="literal">" /&gt;"</span>);            };        };        <span class="reserved">return</span> oDoc;    };    <span class="comment">// see non-IE version   </span>    Sarissa.getParseErrorText = <span class="reserved">function</span> (oDoc) {        var parseErrorText = Sarissa.PARSED_OK;        <span class="reserved">if</span>(oDoc.parseError.errorCode != 0){            parseErrorText = <span class="literal">"XML Parsing Error: "</span> + oDoc.parseError.reason +                 <span class="literal">"\nLocation: "</span> + oDoc.parseError.url +                 <span class="literal">"\nLine Number "</span> + oDoc.parseError.line + <span class="literal">", Column "</span> +                 oDoc.parseError.linepos +                 <span class="literal">":\n"</span> + oDoc.parseError.srcText +                <span class="literal">"\n"</span>;            <span class="reserved">for</span>(var i = 0;  i &lt; oDoc.parseError.linepos;i++){                parseErrorText += <span class="literal">"-"</span>;            };            parseErrorText +=  <span class="literal">"^\n"</span>;        }        <span class="reserved">else</span> <span class="reserved">if</span>(oDoc.documentElement == null){            parseErrorText = Sarissa.PARSED_EMPTY;        };        <span class="reserved">return</span> parseErrorText;    };    <span class="comment">// see non-IE version</span>    Sarissa.setXpathNamespaces = <span class="reserved">function</span>(oDoc, sNsSet) {        oDoc.setProperty(<span class="literal">"SelectionLanguage"</span>, <span class="literal">"XPath"</span>);        oDoc.setProperty(<span class="literal">"SelectionNamespaces"</span>, sNsSet);    };       <span class="comment">/**     * Basic implementation of Mozilla's XSLTProcessor for IE.      * Reuses the same XSLT stylesheet for multiple transforms     * <span class="attrib">@constructor</span>     */</span>    XSLTProcessor = <span class="reserved">function</span>(){        <span class="reserved">if</span>(!_SARISSA_XSLTEMPLATE_PROGID){            _SARISSA_XSLTEMPLATE_PROGID = Sarissa.pickRecentProgID([<span class="literal">"Msxml2.XSLTemplate.6.0"</span>, <span class="literal">"MSXML2.XSLTemplate.3.0"</span>]);        };        <span class="reserved">this</span>.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID);        <span class="reserved">this</span>.processor = null;    };    <span class="comment">/**     * Imports the given XSLT DOM and compiles it to a reusable transform     * &lt;b&gt;Note:&lt;/b&gt; If the stylesheet was loaded from a URL and contains xsl:import or xsl:include elements,it will be reloaded to resolve those     * <span class="attrib">@argument</span> xslDoc The XSLT DOMDocument to import     */</span>    XSLTProcessor.<span class="reserved">prototype</span>.importStylesheet = <span class="reserved">function</span>(xslDoc){        <span class="reserved">if</span>(!_SARISSA_THREADEDDOM_PROGID){            _SARISSA_THREADEDDOM_PROGID = Sarissa.pickRecentProgID([<span class="literal">"MSXML2.FreeThreadedDOMDocument.6.0"</span>, <span class="literal">"MSXML2.FreeThreadedDOMDocument.3.0"</span>]);        };        xslDoc.setProperty(<span class="literal">"SelectionLanguage"</span>, <span class="literal">"XPath"</span>);        xslDoc.setProperty(<span class="literal">"SelectionNamespaces"</span>, <span class="literal">"xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"</span>);        <span class="comment">// convert stylesheet to free threaded</span>        var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID);        <span class="comment">// make included/imported stylesheets work if exist and xsl was originally loaded from url</span>        <span class="reserved">if</span>(xslDoc.url &amp;&amp; xslDoc.selectSingleNode(<span class="literal">"//xsl:*[local-name() = 'import' or local-name() = 'include']"</span>) != null){            converted.async = false;            <span class="reserved">if</span> (_SARISSA_THREADEDDOM_PROGID == <span class="literal">"MSXML2.FreeThreadedDOMDocument.6.0"</span>) {                 converted.setProperty(<span class="literal">"AllowDocumentFunction"</span>, true);                 converted.resolveExternals = true;             }            converted.load(xslDoc.url);        } <span class="reserved">else</span> {            converted.loadXML(xslDoc.xml);        };        converted.setProperty(<span class="literal">"SelectionNamespaces"</span>, <span class="literal">"xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"</span>);        var output = converted.selectSingleNode(<span class="literal">"//xsl:output"</span>);        <span class="reserved">this</span>.outputMethod = output ? output.getAttribute(<span class="literal">"method"</span>) : <span class="literal">"html"</span>;        <span class="reserved">this</span>.template.stylesheet = converted;        <span class="reserved">this</span>.processor = <span class="reserved">this</span>.template.createProcessor();        <span class="comment">// for getParameter and clearParameters</span>        <span class="reserved">this</span>.paramsSet = new Array();    };    <span class="comment">/**     * Transform the given XML DOM and return the transformation result as a new DOM document     * <span class="attrib">@argument</span> sourceDoc The XML DOMDocument to transform     * <span class="attrib">@return</span> The transformation result as a DOM Document     */</span>    XSLTProcessor.<span class="reserved">prototype</span>.transformToDocument = <span class="reserved">function</span>(sourceDoc){        <span class="comment">// fix for bug 1549749</span>        <span class="reserved">if</span>(_SARISSA_THREADEDDOM_PROGID){            <span class="reserved">this</span>.processor.input=sourceDoc;            var outDoc=new ActiveXObject(_SARISSA_DOM_PROGID);            <span class="reserved">this</span>.processor.output=outDoc;            <span class="reserved">this</span>.processor.transform();            <span class="reserved">return</span> outDoc;        }        <span class="reserved">else</span>{            <span class="reserved">if</span>(!_SARISSA_DOM_XMLWRITER){                _SARISSA_DOM_XMLWRITER = Sarissa.pickRecentProgID([<span class="literal">"Msxml2.MXXMLWriter.6.0"</span>, <span class="literal">"Msxml2.MXXMLWriter.3.0"</span>, <span class="literal">"MSXML2.MXXMLWriter"</span>, <span class="literal">"MSXML.MXXMLWriter"</span>, <span class="literal">"Microsoft.XMLDOM"</span>]);            };            <span class="reserved">this</span>.processor.input = sourceDoc;            var outDoc = new ActiveXObject(_SARISSA_DOM_XMLWRITER);            <span class="reserved">this</span>.processor.output = outDoc;             <span class="reserved">this</span>.processor.transform();            var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);            oDoc.loadXML(outDoc.output+<span class="literal">""</span>);            <span class="reserved">return</span> oDoc;        };    };        <span class="comment">/**     * Transform the given XML DOM and return the transformation result as a new DOM fragment.     * &lt;b&gt;Note&lt;/b&gt;: The xsl:output method must match the nature of the owner document (XML/HTML).     * <span class="attrib">@argument</span> sourceDoc The XML DOMDocument to transform     * <span class="attrib">@argument</span> ownerDoc The owner of the result fragment     * <span class="attrib">@return</span> The transformation result as a DOM Document     */</span>    XSLTProcessor.<span class="reserved">prototype</span>.transformToFragment = <span class="reserved">function</span> (sourceDoc, ownerDoc) {        <span class="reserved">this</span>.processor.input = sourceDoc;        <span class="reserved">this</span>.processor.transform();        var s = <span class="reserved">this</span>.processor.output;        var f = ownerDoc.createDocumentFragment();        <span class="reserved">if</span> (<span class="reserved">this</span>.outputMethod == <span class="literal">'text'</span>) {            f.appendChild(ownerDoc.createTextNode(s));        } <span class="reserved">else</span> <span class="reserved">if</span> (ownerDoc.body &amp;&amp; ownerDoc.body.innerHTML) {            var container = ownerDoc.createElement(<span class="literal">'div'</span>);            container.innerHTML = s;            <span class="reserved">while</span> (container.hasChildNodes()) {                f.appendChild(container.firstChild);            }        }        <span class="reserved">else</span> {            var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);            <span class="reserved">if</span> (s.substring(0, 5) == <span class="literal">'&lt;?xml'</span>) {                s = s.substring(s.indexOf(<span class="literal">'?&gt;'</span>) + 2);            }            var xml = <span class="literal">''</span>.concat(<span class="literal">'&lt;my&gt;'</span>, s, <span class="literal">'&lt;/my&gt;'</span>);            oDoc.loadXML(xml);            var container = oDoc.documentElement;            <span class="reserved">while</span> (container.hasChildNodes()) {                f.appendChild(container.firstChild);            }        }        <span class="reserved">return</span> f;    };        <span class="comment">/**     * Set global XSLT parameter of the imported stylesheet     * <span class="attrib">@argument</span> nsURI The parameter namespace URI     * <span class="attrib">@argument</span> name The parameter base name     * <span class="attrib">@argument</span> value The new parameter value     */</span>    XSLTProcessor.<span class="reserved">prototype</span>.setParameter = <span class="reserved">function</span>(nsURI, name, value){        <span class="comment">// nsURI is optional but cannot be null </span>        <span class="reserved">if</span>(nsURI){            <span class="reserved">this</span>.processor.addParameter(name, value, nsURI);        }<span class="reserved">else</span>{            <span class="reserved">this</span>.processor.addParameter(name, value);        };        <span class="comment">// update updated params for getParameter </span>        <span class="reserved">if</span>(!<span class="reserved">this</span>.paramsSet[<span class="literal">""</span>+nsURI]){            <span class="reserved">this</span>.paramsSet[<span class="literal">""</span>+nsURI] = new Array();        };        <span class="reserved">this</span>.paramsSet[<span class="literal">""</span>+nsURI][name] = value;    };    <span class="comment">/**     * Gets a parameter if previously set by setParameter. Returns null     * otherwise     * <span class="attrib">@argument</span> name The parameter base name     * <span class="attrib">@argument</span> value The new parameter value     * <span class="attrib">@return</span> The parameter value if reviously set by setParameter, null otherwise     */</span>    XSLTProcessor.<span class="reserved">prototype</span>.getParameter = <span class="reserved">function</span>(nsURI, name){        nsURI = nsURI || <span class="literal">""</span>;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -