Extra Lines appearing while loading an xml in ie 11 - javascript

Recently I was facing an issue while loading an xml in IE11.So I went through different links and solved the issue and now the xml is getting loaded but multiple blank rows are appearing.
I do not have any clue how this issue can be solved.
I am providing below the code which I am using to load the xml in IE11 and also the screenshot with multiple blank rows:
Code:
function loadXMLDoc(fname)
{
var xmlDoc;
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var nameOffset, verOffset, ix;
// code for IE
if (window.ActiveXObject!=="undefined")
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
if ((verOffset = nAgt.indexOf("Chrome")) == -1 || (verOffset = nAgt.indexOf("Safari")) == -1)
{
xmlDoc.async = false;
xmlDoc.load(fname);
return(xmlDoc);
}
}
function displayResult(xmlData)
{
xml = loadXMLDoc(xmlData);
xsl = loadXMLDoc("finalsheet.xsl");
// code for IE
if (window.ActiveXObject!=="undefined")
{
ex = xml.transformNode(xsl);
return ex;
}
Here is a screenshot of the issue, XML is getting displayed with multiple blank rows above and below the data

Related

HowTo perform XSLT transform on XML from TextArea

I am struggling to perform an XSLT transform in the browser using just html and javascript (I have tried many different ways and none of them work). Here is what I want (and I just can't make it work).
1) I have an XSLT transform, I can make it available as a file (e.g. xslt), I can embed it in the HTML (I don't care), it is static.
2) I want the user to enter their XML into a text area.
3) I want the user to press a button and then I want the XSLT to occur and the result (which is html) to be displayed in a new tab.
Thanks for your help.
Finally got my own javascript to work. Here it is for anyone who needs it.
/**
* Load an XML document from server
*
* #param filename filename
*
* #return DOMDocument
*/
function loadXMLDoc(filename) {
if ((window.ActiveXObject) || (!(window.ActiveXObject) && "ActiveXObject" in window)) {
xhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
else {
xhttp = new XMLHttpRequest();
}
xhttp.open("GET", filename, false);
try {
xhttp.responseType = "msxml-document"
}
catch (err) { } // Helping IE11
xhttp.send("");
return xhttp.responseXML;
}
/**
* Text XML template: perform XSLT on user XML
*
*/
function testXMLTemplate() {
// create xml string from user xml in text area
var xmlstr = document.getElementById("test-xml").value;
xmlstr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xmlstr;
// load XSLT doc
var xsldoc = loadXMLDoc("xml/paramToHtml.xslt")
if ((window.ActiveXObject) || (!(window.ActiveXObject) && "ActiveXObject" in window)) {
// code for IE
var xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmldoc.async = false;
xmldoc.loadXML(xmlstr);
ex = xmldoc.transformNode(xsldoc);
var xmlTestWin = window.open();
xmlTestWin.document.write(ex);
}
else if (document.implementation && document.implementation.createDocument) {
// code for Chrome, Firefox, Opera, etc.
var xmlparser = new DOMParser();
var xmldoc = xmlparser.parseFromString(xmlstr, "text/xml");
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsldoc);
resultDocument = xsltProcessor.transformToDocument(xmldoc);
var xmlTestWin = window.open();
xmlTestWin.document.write(resultDocument.firstChild.innerHTML);
}
}

Dynamics CRM 2015 Online: SubGrid's control.SetParameter method is not available

I'm trying to populate a subgrid with fetchXml results in CRM 2015 online. One issue in the beginning was that document.getElementById("leadUmbrellaGrid"); returns null
function filterSubGrid() {
var leadwithSameNameGrid = Xrm.Page.getControl("leadUmbrellaGrid").getGrid();//HAVE TRIED window.parent.document.getElementById("leadUmbrellaGrid"); //grid to filter
var currentleadId = Xrm.Page.data.entity.getId();;
if (leadwithSameNameGrid == null) {
setTimeout('filterSubGrid()', 500);
return;
}
//fetch xml code
var fetchXml = "<fetchxml goes here>";
leadwithSameNameGrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
leadwithSameNameGrid.control.refresh(); //refresh the sub grid using the new fetch xml
}
I have gone through this and this
I tried window.parent.document.getElementById as well but in both cases, the .control is null or undefined and end up with:
TypeError: Unable to get property 'SetParameter' of undefined or null reference
Would appreciate your help/tips.
Thanks,
Here's the solution:
We need to use window.parent.document.getElementById
Wait for the control to load in the DOM.
So the code would look like this:
function filterSubGrid()
{
var leadwithSameNameGrid = window.parent.document.getElementById("leadUmbrellaGrid");
var currentleadId = Xrm.Page.data.entity.getId();;
if (leadwithSameNameGrid == null)
{
setTimeout(filterSubGrid, 500);
return;
}
//fetch xml code
var fetchXml = "<fetchxml goes here>";
if (leadwithSameNameGrid.control != null)
{
leadwithSameNameGrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
leadwithSameNameGrid.control.refresh(); //refresh the sub grid using the new fetch xml
}
else
{
setTimeout(filterSubGrid, 500);
}
}
function filterSubGrid() {
var leadwithSameNameGrid = window.parent.document.getElementById("leadUmbrellaGrid");
var currentleadId = Xrm.Page.data.entity.getId();;
if (leadwithSameNameGrid == null) {
setTimeout('filterSubGrid()', 500);
return;
}
//fetch xml code
var fetchXml = "<fetchxml goes here>";
if (relatedProjectsSubGrid.control != null) {
leadwithSameNameGrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
leadwithSameNameGrid.control.refresh(); //refresh the sub grid using the new fetch xml
} else {
setTimeout('filterSubGrid()', 500);
}
}
Ive tried this one but didn't quite get where did you get the "relatedProjectsSubGrid.control", also is this still working for CRM 7.1?
Thanks

AJAX File Upload with XMLHttpRequest that support i.e 9

I am trying to upload a file using ajax. The code below works perfectly on all browsers except i.e 9 and previous versions. Unfortunately I am forced to support these browsers so I am wondering how I could modify this code so it will work on i.e.
I have seen some posts suggest using an iframe but i fail to see how this fixes my problem.
I have tried using fileInput.name since it seems that i.e doesn't allow me to have an array of files, this meant that I could actually get to the line where it sends but I wasn't sure what that line should be. xhr.send(fileInput); didn't seem to work.
Also attempted using formdata but then also fould that ie9 didn't support that.
Your help would be greatly appreciated.
<script>
function uploadFile(fileInput, label1, label2, filename) {
var fileInput = document.getElementById(fileInput);
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open('POST', 'Create/Upload');
xhr.setRequestHeader('Content-type', 'multipart/form-data');
//Appending file information in Http headers
//xhr.setRequestHeader('X-File-Name', filename);
xhr.setRequestHeader('X-File-Type', fileInput.files[0].name);
xhr.setRequestHeader('X-File-Type', fileInput.files[0].type);
xhr.setRequestHeader('X-File-Size', fileInput.files[0].size);
xhr.setRequestHeader('X-Type', label1);
//Sending file in XMLHttpRequest
xhr.send(fileInput.files[0]);
//xhr.send(fileInput);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
$('#' + label1).text(xhr.responseText.replace(/\"/g, ""));
document.getElementById(label1).style.color = "green";
document.getElementById(label2).style.display = 'none';
}
else {
$('#' + label1).text("File upload failed");
document.getElementById(label1).style.color = "red";
}
}
}
document.getElementById('uploaderAuto').onsubmit = function () {
myfile = $('#fileInputAuto').val();
var ext = myfile.split('.').pop();
ext = ext.toLowerCase();
if (ext == "pdf" || ext == "docx" || ext == "doc" || ext == "odf" || ext == "rtf") {
uploadFile('fileInputAuto', 'Auto', "AutoView", myfile);
} else {
alert("The following is a list of accepted file types:\n\n - Word Document (*.doc)\n - Word Document (*.docx)\n - Portable Document Format (*.pdf)\n - Open Document Format (*.odf)\n - Rich Text Format (*.rtf)\n\nPlease choose a file with one of these file types.");
}
return false;
}
document.getElementById('uploaderOther1').onsubmit = function () {
myfile = $('#fileInputOther1').val();
uploadFile('fileInputOther1', 'Other1', 'Other1View', myfile);
return false;
}
document.getElementById('uploaderOther2').onsubmit = function () {
myfile = $('#fileInputOther2').val();
uploadFile('fileInputOther2', 'Other2', 'Other2View', myfile);
return false;
}
</script>
I ended up using the script from here: http://www.phpletter.com/Our-Projects/AjaxFileUpload/ and it works very well.
I was using asp.net server side so this tutorial helped: http://totalpict.com/b/asp.net%20generic/5/34396

load an xml file using javascript i

i am trying to upload an xml file using javascript. my javascript code is given below:
var xmlDoc =null;
var abc = new Array();
if (window.ActiveXObject){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument){
xmlDoc=document.implementation.createDocument("","",null);
}
else{
alert('Browser cannot handle this script');
}
if (xmlDoc!=null){
xmlDoc.async=false;
xmlDoc.load("employee.xml");
var x = xmlDoc.getElementsByTagName("EMP");
for (i=0;i<x.length;i++)
{
abc[0] = x[0].getElementsByTagName("ID")[0].childNodes[0].nodeValue;
document.write("a is "+abc[0]);
abc[1] = x[0].getElementsByTagName("ID1")[0].childNodes[0].nodeValue;
document.write("<br>b is "+abc[1]);
}
}
and my xml file is:
<EMPLOYEE>
<EMP>
<ID>10.99</ID>
<ID1>20.54</ID1>
</EMP>
</EMPLOYEE>
the code is working properly in IE as well as firefox but in Google Chrome, it is not showing anything. can some one tell me where i am wrong or how to correct it.
In order to get the XML file in Chrome you need to execute a GET. For security reasons you cannot load it in a straight forward manner from the file system. Here's code:
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", xmlsrc, false);
xmlhttp.send(null);
var xmlDoc = xmlhttp.responseXML.documentElement;

xml parsing in firefox not working

I have a xml file whose content is
<?xml version="1.0" encoding="UTF-8"?>
<ReturnMessage>
<root>ReturnMessage</root>
<cancelMessage>Request cancelled. /cancelMessage>
<confirmMessage>Click 'Create Document' to continue.</confirmMessage>
</ReturnMessage>
I load my xml like this
var result = responseText;
if (document.implementation && document.implementation.createDocument)
{
alert("firefox");
xml=document.implementation.createDocument("","",null);
xml.load(result);
}
When execute the below code
var cnfmMsgCnt = xml.getElementsByTagName("confirmMessage");
alert(cnfmMsgCnt.lenght);
it alerts a 0 is firefox.
var displayMsg = xml.getElementsByTagName("confirmMessage").item(0).text
also does not provide any output in FF.
It works perfect in IE but it is not working in Firefox.
The method load() takes a file name as argument, not an XML string. See https://developer.mozilla.org/en/DOM/document.load (and more normative: W3C DOM Level 3 Load & Save module)
What you probably want is explained here https://developer.mozilla.org/en/Parsing_and_serializing_XML
var sMyString = "<a id=\"a\"><b id=\"b\">hey!<\/b><\/a>";
var oParser = new DOMParser();
var oDOM = oParser.parseFromString(sMyString, "text/xml");

Categories