简体   繁体   English

XML解析后的“对象”与“对象文档”,IE 9不接受

[英]“Object” vs “Object Document” after XML parsing, not accepted by IE 9

I am facing an issue after XML parse in IE9. 在IE9中进行XML解析后,我面临一个问题。 When I alerted the variable where I have parsed the XML, in all the other browser except IE9 I can see the text [Object] but in IE9 it is showing me [Object Document]. 当我向我解析XML的变量发出警报时,在除IE9之外的所有其他浏览器中,我都可以看到文本[Object],但是在IE9中,它显示的是[Object Document]。 For this reason the variable value is not assigned to input parameter. 因此,变量值未分配给输入参数。 Code: 码:

if (window.DOMParser)
  {
  parser=new DOMParser();
  xmlDoc=parser.parseFromString(txt,"text/xml");
  }
else // Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.loadXML(txt); 
  }


xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;

In IE9 I can see the IF block is executing every time, xmlDoc alerted as [Object Document] [in IE9 only], and the code stopped when I assigned the xmlDoc object in input parameter (last line), all other browsers including IE7, IE8 running fine. 在IE9中,我可以看到IF块每次都在执行,xmlDoc被警告为[Object Document] [仅在IE9中],并且当我在输入参数(最后一行),所有其他浏览器(包括IE7)中分配xmlDoc对象时,代码停止了IE8运行正常。 Any help will be appreciated. 任何帮助将不胜感激。 Thanks in advance. 提前致谢。

EDIT: XSLT format 编辑: XSLT格式

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" />
    <xsl:param name="selectedSKU"></xsl:param>
    <xsl:param name="pageName">skuset</xsl:param>
    <xsl:param name="selectedSWATCH"></xsl:param>
    <xsl:param name="colFlag">0</xsl:param>
    <xsl:param name="xslStoreId">10001</xsl:param>
    <xsl:param name="xslLangId">-1</xsl:param>
    <xsl:param name="xslCatalogId">10051</xsl:param>
    <xsl:param name="exitURL"></xsl:param>
    <xsl:param name="iskiosk">0</xsl:param>

    <xsl:param name="AddToCart"></xsl:param>
    <xsl:param name="Qty"></xsl:param>

    <xsl:template match="/">
        <xsl:apply-templates select="//product[@id=$selectedSKU]" />
    </xsl:template>
    <xsl:variable name="label_stars">
        <xsl:value-of select="productcatalog/labels/label[@key='common.stars']" />
    </xsl:variable>
    <xsl:variable name="label_reviews">
        <xsl:value-of select="productcatalog/labels/label[@key='common.reviews']" />
    </xsl:variable>
</xsl:stylesheet> 

The XSLT file is preety long...so I have attached one block with it. XSLT文件太长了……所以我已经附加了一个块。

IE versions before IE 9 don't have its own XML parser but rather can use any version of MSXML to parse XML. IE 9之前的IE版本没有自己的XML解析器,而是可以使用任何版本的MSXML来解析XML。 MSXML (since version 3) also supports XSLT transformations. MSXML(从版本3开始)也支持XSLT转换。

With IE 9 IE now has its own XML parser you can use from script with DOMParser to construct XML DOM documents. 借助IE 9,IE现在拥有自己的XML解析器,您可以将脚本与DOMParser一起使用来构造XML DOM文档。 However IE has no own support to apply XSLT transformations on such documents and MSXML does not work with IE's DOM documents as input to XSLT. 但是,IE没有自己的支持将XSLT转换应用于此类文档,并且MSXML不能与IE的DOM文档一起用作XSLT的输入。

Thus if you want to use XSLT with IE 9 you need to make sure you construct an MSXML DOM document with new ActiveXObject('Microsoft.XMLDOM') (respectively new ActiveXObject('Msxml2.DOMDocument.3.0') is recommended these days) and not with DOMParser . 因此,如果要将XSLT与IE 9结合使用,则需要确保使用new ActiveXObject('Microsoft.XMLDOM')new ActiveXObject('Msxml2.DOMDocument.3.0')建议分别使用new ActiveXObject('Msxml2.DOMDocument.3.0')构建MSXML DOM文档。不能与DOMParser So basically your feature check if (window.DOMParser) is not the right approach if you want to apply XSLT with a browser, rather use eg 因此,基本上,如果您想将XSLT与浏览器一起使用,则使用功能检查if (window.DOMParser)是否不是正确的方法,而应使用例如

var input;

if (window.XSLTProcessor && window.DOMParser) {
  input = new DOMParser().parseFromString(txt, 'application/xml');
}
else if (window.ActiveXObject) {
  input = new ActiveXObject('Msxml2.DOMDocument.3.0');
}

if (input) {
  xslProc = xslt.createProcessor();
  xslProc.input = input;
  ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM