how to use DomParser and Transform xml -xslt in ie9

已答复 how to use DomParser and Transform xml -xslt in ie9

  • Thursday, June 07, 2012 6:03 PM
     
     

    Hi, I have found lot of links which uses following script to transform

    Code 1

    <script language="javascript"> 
       
    function displayMessage() { 
           
    // Load XML  
     
           
    var xml = new ActiveXObject("Microsoft.XMLDOM") 
            xml
    .async = false 
            xml
    .load("site-index.xml") 
     
           
    // Load the XSL 
           
    var xsl = new ActiveXObject("Microsoft.XMLDOM") 
            xsl
    .async = false 
            xsl
    .load("site-index.xsl") 
     
           
    // Transform 
            document
    .write(xml.transformNode(xsl)) 
       
    } 
    </script> 

    I want to rewrite the above code so that it can work on all the browser such as chrome,Firefox , IE9 .

    So i will need to use xmlSerialization

    I got a code for XMLSerialization  which is as per following.

    Code2

    // Parse a string into an XML document
    var parser = new DOMParser();

    var doc = parser.parseFromString("<myXML/>", "text/xml");

    // Serialize any native DOM node to an XML string
    // (including nodes from HTML documents)
    var serializer = new XMLSerializer();
    var xmlString = serializer.serializeToString(doc);

    I have two questions for code2  

    •  can we use xml file directly instead of passing xmlstring(var doc = parser.parseFromString("<myXML/>", "text/xml");) or is there any way by which we can load xml file from local machine as shown in Code1 .
    • in IE9 how we can transform xml-xslt as per given in Code1(document.write(xml.transformNode(xsl))).

    Thanks....
     


    Prashant



All Replies