Workaround for xml data

I recently inherited a huge webapp, which is a combination of JSP, Javascript, and Java. It only works on IE because of how it was encoded using the xml data of the islands and other things that prevent smooth operation in other browsers. Everything was fine until a few days when Windows 7 mailboxes were deployed to multiple users in which IE9 / 10 has problems with some of the javascript in the application. For example, the next data island is a snippet from my html page.

<xml id = "underlyingdata" ondatasetcomplete="window.dialogArguments.parent.repopulateDropDown(this, underlyingdd)"> </xml> <xml id="termdata" ondatasetcomplete="window.dialogArguments.parent.repopulateDropDown(this, termdd)"> </xml> 

There is another line of code on this page.

 window.dialogArguments.parent.request(underlyingdata, "CONTRACT.LIST.WB", "PULP AND PAPER|" + instrumentdd.options[instrumentdd.selectedIndex].text); 

which calls a function that looks like this

 function request(xmldataisland, requestmethod, parameters { var screwcache=Math.round(Math.random()*10000); xmldataisland.value=null; xmldataisland.load("/webaccess/Request?sessionid=" + sessionid + "&request=" + requestmethod + "&parameters=" + parameters+"&screwcache="+screwcache); } 

This does not work in IE9 / 10 with the error that "load" is not a valid method (Script error 438) on the "xmldataisland" object, whereas it works fine in IE 5 through IE 8.

I believe that the xmldataisland object in the above function is of type XMLDocument. Why doesn't the boot method work? What is the workaround for this? I read and hear from many sources that using data islands is a terrible idea. What would be a suitable alternative for this in this case?

+4
source share
1 answer

From IE10 onwards , the XML data islands are no longer supported - the browser parses them as HTML. An article has been published on the Mozilla Developer Network that provides an alternative to XML data islands, namely the HTML5 data block. The article shows that the <script> element can be used as a data block if the src attribute is not specified and the type attribute does not indicate the executable type of the script. You must also ensure that the embedded XML content does not contain the </script> .

Source: https://developer.mozilla.org/en/docs/Using_XML_Data_Islands_in_Mozilla

Here is an example of the HTML they give ...

 <!DOCTYPE html> <html> <head> <title>XML Data Block Demo</title> <!-- this is the data block which contains the XML data --> <script id="purchase-order" type="application/xml"> <purchaseOrder xmlns="http://example.mozilla.org/PurchaseOrderML"> <lineItem> <name>Line Item 1</name> <price>1.25</price> </lineItem> <lineItem> <name>Line Item 2</name> <price>2.48</price> </lineItem> </purchaseOrder> </script> <script> function runDemo() { // the raw XML data can be retrieved using this... var orderSource = document.getElementById("purchase-order").textContent; // the XML data can be parsed into a DOM tree using the DOMParser API... var parser = new DOMParser(); var doc = parser.parseFromString(orderSource, "application/xml"); var lineItems = doc.getElementsByTagNameNS("http://example.mozilla.org/PurchaseOrderML", "lineItem"); var firstPrice = lineItems[0].getElementsByTagNameNS("http://example.mozilla.org/PurchaseOrderML", "price")[0].textContent; document.body.textContent = "The purchase order contains " + lineItems.length + " line items. The price of the first line item is " + firstPrice + "."; } </script> </head> <body onload="runDemo()";> Demo did not run </body> </html> 

You will need to write your own method to load data into this block (possibly using jQuery.get or .load ).

Hope this helps!

+8
source

Source: https://habr.com/ru/post/1501713/


All Articles